package system.servlet;


import java.io.IOException;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.Region;

import system.base.Customer;
import system.base.ProductCategory;
import system.base.Warehouse;
import system.base.WarehouseCategory;
import system.base.WarehouseCategoryRelation;
import system.report.ReportYKProductMonth;
import system.until.DoubleUtil;


import com.apep.jwcs.service.AirSortReportExcel;
import com.apep.jwcs.service.AirSortReportService;

import com.hitrust.gs.lib.GSAutoAuditongDateConfigurator;
import com.hitrust.gs.lib.GSBaseConstants;

import com.hitrust.gs.util.ResponseUtils;
import com.hitrust.gs.util.exception.GSException;

import framework.core.ConstDefine;
import framework.core.DBConnection;
import framework.core.DBEngine;
import framework.core.DBResult;
import framework.core.DateUtil;
import framework.core.LogWriter;
import framework.core.ObjectList;
import framework.core.SrvContext;
import framework.core.StringUtil;
import framework.core.UniversalRow;
import framework.core.UniversalTable;

public class ReportServlet extends HttpServlet {
	private static final long serialVersionUID = 1;// 仅为不让本类出现警告 unnecessary
	private static final String IS_REPORT_PROCESSING = "isReportProcessing";

	public void init(ServletConfig aConfig) throws ServletException {
		super.init(aConfig);
	}

	// ==================================================报表1 开始
	/**
	 * 报表1调用 根据起始时间 得到入库单纪录中 符合条件的供应商列表
	 */
	public Vector detailqueryProviderGroup(String warehouseCode, String start, String end, String providerName, boolean needall, String balance_mode) {
		boolean provider = !providerName.equals("") && providerName != null;// 供应商是否存在
		String providertrue = "select code,name from t_provider where name = '" + providerName + "'";
		String sqlStart = " select a.code,(select name from t_provider where t_provider.code = a.code) name from( ";
		String sqlInStart = " select " + " inhead.provider_code code, " + " inhead.provider_name name " + " from " + " t_in_head inhead, " + " t_in_sub insub "
		+ " where " + " inhead.in_bill_code = insub.in_bill_code " + " and " + " inhead.warehouse_code like '" + warehouseCode + "%' "
		+ " and insub.balance_mode = '" + balance_mode + "' " +

		" and " + " insub.status = '1' ";
		String sqlInEnd = " group by inhead.provider_code,inhead.provider_name ";
		String inneedallfalse = " and inhead.in_time >= '" + start + "' " + " and " + " inhead.in_time <= '" + end + "' ";
		String sqlOutStart = " select " + " per.code code, " + " per.name name " + " from " + " t_out_head outhead, " + " t_out_sub outsub, "
		+ " t_provider per " + " where " + " outhead.out_bill_code = outsub.out_bill_code " + " and " + " outhead.warehouse_code like '"
		+ warehouseCode + "%' " + " and " + " outsub.status = '1' " + " and " + " per.code = outsub.provider_code " + " and outsub.balance_mode = '"
		+ balance_mode + "' ";

		String sqlOutEnd = " group by per.code,per.name ";
		String outneedallfalse = " and outhead.out_time >= '" + start + "' and outhead.out_time <= '" + end + "' ";
		String sqlEnd = " ) a group by code order by code ";
		String sql = "";
		if (needall) {// 需要所有数据
			if (provider) {
				sql = providertrue;
			} else {
				sql = sqlStart + sqlInStart + sqlInEnd + " union all " + sqlOutStart + sqlOutEnd + sqlEnd;
			}
		} else {// 不需要所有数据
			if (provider) {
				sql = providertrue;
			} else {
				sql = sqlStart + sqlInStart + inneedallfalse + sqlInEnd + " union all " + sqlOutStart + outneedallfalse + sqlOutEnd + sqlEnd;
			}
		}
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		DBResult dbrs = null;
		ResultSet row = null;
		Vector vec = new Vector();
		try {
			dbrs = DBEngine.doSelect(con, sql);
			row = dbrs.getRs();
			while (row.next()) {
				ProviderTemp pt = new ProviderTemp();
				pt.providerCode = row.getString(1);
				pt.ProviderName = row.getString(2);
				vec.add(pt);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				row.close();
				dbrs.clear();
				con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return vec;
	}

	// ==================================================报表1 结束

	// ==================================================报表2 开始
	/**
	 * 被报表2调用 查询出库涉及到的客户
	 */
	public ObjectList detailquery2Group(String warehouseCode, String customerCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String orgLimitCond2 = "";
		if (customerCode.equals("00")) {
			orgLimitCond2 = "1=1";
		} else {
			orgLimitCond2 = "substr(b.get_customer_code,1," + customerCode.length() + ") = " + customerCode;
		}

		String sql = "select b.get_customer_code cc from t_out_head a,t_out_sub b,t_customer c "
			+ "where b.status = '1' and a.id = b.out_bill_id and b.get_customer_code = c.code " + "and a.warehouse_code like '" + warehouseCode
			+ "%' and (" + orgLimitCond2 + ")";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		sql += " group by b.get_customer_code";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery2Group error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {
			}
		}
		return mReturn;
	}

	/**
	 * 被报表2调用 查询产品出库金额
	 */
	public ObjectList detailquery2(String warehouseCode, String customerCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String orgLimitCond2 = "";
		if (customerCode.equals("00")) {
			orgLimitCond2 = "1=1";
		} else {
			orgLimitCond2 = "substr(b.get_customer_code,1," + customerCode.length() + ") = " + customerCode;
		}
		String sql = "select c.code code,c.name name,b.product_money money " + "from t_out_head a,t_out_sub b,t_customer c "
		+ "where b.status = '1' and a.id = b.out_bill_id and b.get_customer_code = c.code " + "and a.warehouse_code like '" + warehouseCode
		+ "%' and (" + orgLimitCond2 + ")";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();

		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery2 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}
		return mReturn;
	}
	

	/**
	 * 被报表2调用 查询产品出库金额
	 */
	public ObjectList detailqueryDetail(String warehouseCode, String customerCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String orgLimitCond2 = "";
		if (customerCode.equals("00")) {
			orgLimitCond2 = "1=1";
		} else {
			orgLimitCond2 = "substr(b.get_customer_code,1," + customerCode.length() + ") = " + customerCode;
		}
		String sql = "select b.product_code productCode,b.product_name productName,d.spec spec,d.model model,d.product_brand productBrand,d.product_unit productUnit,d.unit_price unitPrice, " 
			+ "  c.code code, c.name name,b.product_count productCount, b.product_money money from t_out_head a,t_out_sub b,t_customer c,t_product d "
		+ "where  b.product_code=d.concentricity_code and b.status = '1' and a.id = b.out_bill_id and b.get_customer_code = c.code " + "and a.warehouse_code like '" + warehouseCode
		+ "%' and (" + orgLimitCond2 + ")";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "' order by c.code ";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();

		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery2 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}
		return mReturn;
	}

	// ==================================================报表2 结束

	// ==================================================报表4 开始
	public ObjectList detailquery4Group(String warehouseCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.code provider_code " + "from " + "t_out_head a," + "t_out_sub b," +
		// "t_product c," +//修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " +
		// "and b.product_id = c.id " +
		// "and c.provider_code = d.code " + //修改供应商条件查询
		"and b.provider_code = d.code " + // 修改供应商条件查询
		"and a.warehouse_code like '" + warehouseCode + "%' " + "and b.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "'";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		sql += " group by d.code";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery4Group error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {
			}
		}
		return mReturn;
	}

	public ObjectList detailquery4true(String warehouseCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}
		sql = sql + "from " + "t_out_head a," + "t_out_sub b,"
		+ "t_product c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " + "and b.product_id = c.id " + "and b.provider_code = d.code "
		+ "and a.warehouse_code like '" + warehouseCode + "%' " + "and b.balance_mode = '" + ConstDefine.getBalanceModeByFlag()
		+ "' and (c.IS_TRADEFLAT_PRODUCT = '1' or c.IS_TRADEFLAT_PRODUCT = '0') ";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery4 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}
		return mReturn;
	}
	
	public ObjectList detailqueryOutYK(String warehouseCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";

		sql = sql + "b.product_money money ";
		sql = sql + "from " + "t_out_head a," + "t_out_sub b,"
		+ "t_product c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " + "and b.product_id = c.id " + "and b.provider_code = d.code "
		+ "and a.warehouse_code like '" + warehouseCode + "%' " + "and b.balance_mode = '" + ConstDefine.getBalanceModeByFlag()
		+ "' and (c.IS_TRADEFLAT_PRODUCT = '1' or c.IS_TRADEFLAT_PRODUCT = '0') ";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery4 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}
		return mReturn;
	}

	public ObjectList detailquery4false(String warehouseCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}

		sql = sql + "from " + "t_out_head a," + "t_out_sub b," + "t_product c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " + "and b.product_id = c.id " + "and b.provider_code = d.code "
		+ // 修改供应商条件查询
		"and a.warehouse_code like '" + warehouseCode + "%' " + "and b.balance_mode = '" + ConstDefine.getBalanceModeByFlag()
		+ "' and c.IS_TRADEFLAT_PRODUCT = '2'";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";

		DBConnection con = null;

		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();

		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery4 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}

		return mReturn;
	}

	// ==================================================报表4 结束

	// ==================================================报表6 开始
	public ObjectList detailquery6Group(String warehouseCode, String inCustomerName, String getCustomers, String start, String end) {

		ObjectList mReturn = ObjectList.getList();
		String cusLimit = "";
		if ("".equals(getCustomers)) {
			cusLimit = "1=1";
		} else {
			cusLimit = "b.get_customer_code in (" + getCustomers + ")";
		}

		String sql = "select b.product_code code from t_out_head a,t_out_sub b,t_product c,t_customer d "
			+ "where a.id = b.out_bill_id and b.product_code = c.concentricity_code and a.customer_code = d.code " + "and a.warehouse_code like '"
			+ warehouseCode + "%'" + "and d.name = '" + inCustomerName + "' and " + cusLimit;
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "' ";
		sql += "group by b.product_code";

		DBConnection con = null;

		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();

		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery6Group error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}

		return mReturn;
	}

	public ObjectList detailquery6All(String warehouseCode, String inCustomerName, String getCustomers, String start, String end) {

		ObjectList mReturn = ObjectList.getList();
		String cusLimit = "";
		if ("".equals(getCustomers)) {
			cusLimit = "1=1";
		} else {
			cusLimit = "b.get_customer_code in (" + getCustomers + ")";
		}
		String sql = "select b.product_code concentricity_code,c.apep_code apep_code,c.name name,c.spec spec,b.product_price price, "
			+ "b.product_count count,b.product_money money " + "from t_out_head a,t_out_sub b,t_product c,t_customer d "
			+ "where a.id = b.out_bill_id and b.product_code = c.concentricity_code and a.customer_code = d.code " + "and a.warehouse_code like '"
			+ warehouseCode + "%'" + "and d.name = '" + inCustomerName + "' and " + cusLimit;
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery6All error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}

		return mReturn;
	}

	// ==================================================报表6 结束

	/** 开始执行报表 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
		if(!isProcessContinue(request, response)){
			return;
		}

		HttpSession session = request.getSession();
		session.setAttribute(IS_REPORT_PROCESSING, Boolean.TRUE);


		System.out.println("**ReportServlet start**");
		/** 时间拼接 开始************************************************** */
		String tDateString = new DateUtil().getFullString();
		String tYear = tDateString.substring(0, 4);
		String tMonth = tDateString.substring(5, 7);
		String tDate = tDateString.substring(8, 10);
		String tHour = tDateString.substring(11, 13);
		String tMin = tDateString.substring(14, 16);
		String tSec = tDateString.substring(17, 19);
		String fileName = "GW_REPORT_" + tYear + "_" + tMonth + "_" + tDate + "_" + tHour + "_" + tMin + "_" + tSec;
		/** 时间拼接 结束************************************************** */

		/** 基础变量设置 开始************************************************* */
		String providerName = ""; // 供应商名称
		String inCustomerName = ""; // 供货单位名称
		String customerCode = ""; // 领料单位编码
		// String warehouseProduct = ""; //报表分类 此变量 使用地不明确 暂注释
		String getCustomers = "";// 领料单位
		String title = request.getParameter("title");
		String warehouseCode = ""; // 仓库编码
		String start = ""; // 查询起始时间
		String end = ""; // 查询终止时间
		String needAll = "";// 查询所有的纪录
		/** 基础变量设置 结束************************************************* */

		/**
		 * title : 1.压库产品进、销、存报表 2.领用报表 3.压库产品进、销、存资金汇总月报 4.压库产品应付款月报
		 * 5.买断产品资金进出累计汇总（成本价） 6.合并库收料清单（修理公司） 7.压库产品分类月进出明细
		 * 8.买断产品资金进出累计汇总(账本分类统计) 10.买断产品进销存报表（因为9被用掉了） 16.空调报表(11-15下面有被用掉)
		 * 18.产品进销存供应商分类报表,19.供应商应付报表
		 */
		/** 压库产品进销存报表 对供应商参数进行判断 开始 */
		if ("1".equals(title)||"10".equals(title)||"18".equals(title)) {
			if (!"".equals(request.getParameter("providerName")) && request.getParameter("providerName") != null) {
				try {
					providerName = request.getParameter("providerName");
					providerName = SrvContext.fixString(providerName);
				} catch (Exception e) {
					providerName = "";
				}
			} else {
				providerName = "";
			}
			needAll = request.getParameter("needAll");
		}
		/** 压库产品进销存报表 对供应商参数进行判断 结束 */
		else if ("2".equals(title)) {
			customerCode = request.getParameter("customerCode");
		} else if ("5".equals(title)) {
			if (!"".equals(request.getParameter("warehouseProduct")) && request.getParameter("warehouseProduct") != null){
				// warehouseProduct = request.getParameter("warehouseProduct");
			}
			else{
				// warehouseProduct = "";
			}
		} else if ("6".equals(title)) {
			try {
				inCustomerName = request.getParameter("customerName");
				inCustomerName = SrvContext.fixString(inCustomerName);
			} catch (Exception e) {
				inCustomerName = "";
			}
			if (!"".equals(request.getParameter("getCustomer")) && request.getParameter("getCustomer") != null) {
				getCustomers = request.getParameter("getCustomer");
			}
		} else if("8".equals(title)){
			if (!"".equals(request.getParameter("warehouseProduct")) && request.getParameter("warehouseProduct") != null){
				// warehouseProduct = request.getParameter("warehouseProduct");
			}
			else{
				// warehouseProduct = "";
			}
		}

		if (!"".equals(request.getParameter("warehouseCode")) && request.getParameter("warehouseCode") != null) {
			warehouseCode = request.getParameter("warehouseCode");
		}
		String querytype = request.getParameter("querytype");
		String month = "";
		/** 压库产品进销存报表 对查询时间段进行判断 开始 */
		int sYear = 0;
		int sMonth = 0;
		if ("1".equals(querytype)||"3".equals(querytype)) {
			String yearMonth = request.getParameter("begindate") + "-" + request.getParameter("enddate");
			sYear = Integer.parseInt(request.getParameter("begindate").trim());
			sMonth = Integer.parseInt(request.getParameter("enddate").trim());
			int sDate = 31; // 每月的默认天数
			try {
				sDate = DateUtil.getMaxDayOfMonth(sYear, sMonth);
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			start = yearMonth + "-01";
			end = yearMonth + "-" + String.valueOf(sDate);
			if (String.valueOf(sMonth - 1).length() < 2) {
				month = String.valueOf(sYear) + "0" + String.valueOf(sMonth - 1);
			} else {
				month = String.valueOf(sYear + sMonth);
			}
		} else {
			start = request.getParameter("begindate");
			if ("".equals(request.getParameter("enddate"))) {
				end = new framework.core.DateUtil().getDateString();
			} else {
				end = request.getParameter("enddate");
			}
			int tmpMonth = Integer.parseInt(start.substring(6, 7)) - 1;

			if (String.valueOf(tmpMonth).length() < 2) {
				month = start.substring(0, 4);
				month += "0" + String.valueOf(tmpMonth);
			} else {
				month = start.substring(0, 4);
				month += String.valueOf(tmpMonth);
			}
		}
		/** 压库产品进销存报表 对查询时间段进行判断 结束 */
		String before_end = "";

		if(start.length()<=10){
			start += " 00:00:00";
		}
		if(end.length()<=10){
			end += " 23:59:59";
		}
		before_end = start;
		String title1 = ""; // 表头
		String warehouseName = ""; // 仓库名称
		try {
			DBConnection con = null;
			con = DBConnection.open(false);
			warehouseName = Warehouse.fetchByCode(con, warehouseCode).getName();
			con.close();
		} catch (Exception e2) {
			System.out.println(e2.getMessage());
		}

		System.out.println("start=" + start);
		System.out.println("end=" + end);

		boolean isAvaliable = true;// 是否保存成功
		boolean isLager = false;// 是否数据过多


		/**
		 * 压库产品进销存 数据提取 开始 (9是新的查询逻辑,不同之处是月结的查询) (10是买断产品进销存) (16是空调报表)
		 * 17是按集团分类进销存报表)
		 */
		if("17".equals(title)){
			String balance_mode = request.getParameter("balanceMode");
			String position = request.getParameter("positionCode");
			List warehouesList = new ArrayList();
			warehouesList = WarehouseCategory.getWarehouseCode(warehouseCode);
			int size = 0;
			if(warehouesList != null && warehouesList.size() > 0) {
				size = warehouesList.size();
			}
			int totalSize = 0;
			DBConnection con = null;
			DBResult dbrs = null;
			java.sql.ResultSet rs = null;
			List fullList = new ArrayList();
			try{
				con = DBConnection.open(false);
				for (int i = 0; i < size; i++) {
					String[] currentWarehouseCode = (String[])warehouesList.get(i);

					String sql =
						"SELECT   aa1.category_code, aa1.upper_category, aa1.name,"+
						" SUM (aa1.init_count) init_count, SUM (aa1.init_money) init_money, "+
						" SUM (aa1.in_count) in_count, SUM (aa1.in_money) in_money, "+
						" SUM (aa1.in_1002money) in_1002money, "+
						" SUM (aa1.in_money) + SUM (aa1.in_1002money) in_moneys, "+
						" SUM (aa1.out_count) out_count, SUM (aa1.out_money) out_money, "+
						" SUM (aa1.out_2002money) out_2002money, "+
						" SUM (aa1.out_money) + SUM (aa1.out_2002money) out_moneys, "+
						"  SUM (aa1.init_count) "+
						" + SUM (aa1.in_count) "+
						" - SUM (aa1.out_count) final_count, "+
						"   SUM (aa1.init_money) "+
						" + SUM (aa1.in_money) "+
						" + SUM (aa1.in_1002money) "+
						" - SUM (aa1.out_money) "+
						" - SUM (aa1.out_2002money) final_money "+
						" FROM (SELECT   a.category_code, a.upper_category, a.name, "+
						"  SUM (a.in_count) - SUM (a.out_count) init_count, "+
						" SUM (a.in_money) "+
						" + SUM (a.in_1002money) "+
						" - SUM (a.out_money) "+
						" - SUM (a.out_2002money) init_money,"+
						" 0 in_count, 0 in_money, 0 in_1002money, 0 out_count, "+
						" 0 out_money, 0 out_2002money "+
						" FROM (SELECT   wcr.category_code, wc.upper_category, "+
						" wc.name, 0 init_count, 0 init_money, "+
						" SUM (insub.product_count) in_count, "+
						" SUM (insub.product_money) in_money, "+
						" 0 in_1002money, 0 out_count, 0 out_money, "+
						" 0 out_2002money "+
						" FROM t_in_sub insub LEFT OUTER JOIN t_in_head inhead "+
						" ON insub.in_bill_id = inhead.ID "+
						" LEFT OUTER JOIN t_product wcr "+
						" ON UPPER (insub.product_code) = "+
						" UPPER (wcr.concentricity_code) "+
						" LEFT OUTER JOIN t_product_category wc "+
						" ON wcr.category_code = wc.code "+
						" WHERE 1 = 1 "+
						" AND inhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
						" AND inhead.in_time < '"+start+"' "+
						" AND insub.status = '1' ";
					if(balance_mode!=null&balance_mode.trim().length()>0){
						sql += " and insub.balance_mode = '"+balance_mode.trim()+"' ";
					}
					if(position!=null&position.trim().length()>0){
						sql += " and insub.position_code = '"+position.trim()+"' ";
					}

					sql +=    " GROUP BY wc.upper_category, "+
					" wcr.category_code, "+
					" wc.name "+
					" UNION ALL "+
					" SELECT   wcr.category_code, wc.upper_category, "+
					"  wc.name, 0 init_count, 0 init_money, "+
					"  0 in_count, 0 in_money, 0 in_1002money, "+
					"  SUM (outsub.product_count) out_count, "+
					"  SUM (outsub.product_money) out_money, "+
					" 0 out_1002money "+
					" FROM t_out_sub outsub LEFT OUTER JOIN t_out_head outhead "+
					" ON outsub.out_bill_id = outhead.ID "+
					" LEFT OUTER JOIN t_product wcr "+
					" ON UPPER (outsub.product_code) = "+
					" UPPER (wcr.concentricity_code) "+
					" LEFT OUTER JOIN t_product_category wc "+
					" ON wcr.category_code = wc.code "+
					" WHERE 1 = 1 "+
					" AND outhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
					" AND outhead.out_time < '"+start+"' "+
					" AND outsub.status = '1' ";
					if(balance_mode!=null&balance_mode.trim().length()>0){
						sql += " and outsub.balance_mode = '"+balance_mode.trim()+"' ";
					}
					if(position!=null&position.trim().length()>0){
						sql += " and outsub.position_code = '"+position.trim()+"' ";
					}
					sql += " GROUP BY wc.upper_category, "+
					" wcr.category_code, "+
					"wc.name) a "+
					"GROUP BY upper_category, category_code, name "+
					"UNION ALL "+
					"SELECT a1.category_code, a1.upper_category, a1.name, "+
					" 0 init_count, 0 init_money, a1.in_count, a1.in_money, "+
					"a1.in_1002money, 0 out_count, 0 out_money, 0 out_2002money "+
					"FROM (SELECT   wcr.category_code, wc.upper_category, "+
					" wc.name, "+
					" SUM (insub.product_count) in_count, "+
					" SUM (insub.product_money) in_money, 0 in_1002money "+
					" FROM t_in_sub insub LEFT OUTER JOIN t_in_head inhead "+
					"ON insub.in_bill_id = inhead.ID "+
					"LEFT OUTER JOIN t_product wcr "+
					"ON UPPER (insub.product_code) = "+
					"  UPPER (wcr.concentricity_code) "+
					"LEFT OUTER JOIN t_product_category wc "+
					"ON wcr.category_code = wc.code "+
					"   WHERE 1 = 1 "+
					"AND inhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
					"AND inhead.in_time >= '"+start+"' "+
					"AND inhead.in_time <= '"+end+"' "+
					"AND inhead.in_type = '1001' "+
					"AND insub.status = '1' ";
					if(balance_mode!=null&balance_mode.trim().length()>0){
						sql += " and insub.balance_mode = '"+balance_mode.trim()+"' ";
					}
					if(position!=null&position.trim().length()>0){
						sql += " and insub.position_code = '"+position.trim()+"' ";
					}
					sql +=
						"GROUP BY wc.upper_category,"+
						"wcr.category_code, "+
						"wc.name "+
						"UNION "+
						"SELECT   wcr.category_code, wc.upper_category, "+
						"wc.name, "+
						"SUM (insub.product_count) in_count, 0 in_money, "+
						"SUM (insub.product_money) in_1002money "+
						"    FROM t_in_sub insub LEFT OUTER JOIN t_in_head inhead "+
						"ON insub.in_bill_id = inhead.ID "+
						"LEFT OUTER JOIN t_product wcr "+
						"ON UPPER (insub.product_code) = "+
						"  UPPER (wcr.concentricity_code) "+
						"LEFT OUTER JOIN t_product_category wc "+
						"ON wcr.category_code = wc.code "+
						"   WHERE 1 = 1 "+
						"AND inhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
						"AND inhead.in_time >= '"+start+"' "+
						"AND inhead.in_time <= '"+end+"' "+
						"AND inhead.in_type = '1002' "+
						"AND insub.status = '1' ";
					if(balance_mode!=null&balance_mode.trim().length()>0){
						sql += " and insub.balance_mode = '"+balance_mode.trim()+"' ";
					}
					if(position!=null&position.trim().length()>0){
						sql += " and insub.position_code = '"+position.trim()+"' ";
					}
					sql+=
						"GROUP BY wc.upper_category, "+
						"wcr.category_code, "+
						"wc.name) a1 "+
						"   UNION ALL "+
						"   SELECT a2.category_code, a2.upper_category, a2.name, "+
						"0 init_count, 0 init_money, 0 in_count, 0 in_money, "+
						"0 in_1002money, a2.out_count, a2.out_money, a2.out_1002money "+
						"FROM (SELECT   wcr.category_code, wc.upper_category, "+
						"wc.name, "+
						"SUM (outsub.product_count) out_count, "+
						"SUM (outsub.product_money) out_money, "+
						"0 out_1002money "+
						"    FROM t_out_sub outsub LEFT OUTER JOIN t_out_head outhead "+
						"ON outsub.out_bill_id = outhead.ID  "+
						"LEFT OUTER JOIN t_product wcr "+
						"ON UPPER (outsub.product_code) = "+
						"  UPPER (wcr.concentricity_code) "+
						"LEFT OUTER JOIN t_product_category wc "+
						"ON wcr.category_code = wc.code "+
						"   WHERE 1 = 1 "+
						"AND outhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
						"AND outhead.out_time >= '"+start+"' "+
						"AND outhead.out_time <= '"+end+"' "+
						"AND outhead.out_type = '2001' "+
						"AND outsub.status = '1' ";
					if(balance_mode!=null&balance_mode.trim().length()>0){
						sql += " and outsub.balance_mode = '"+balance_mode.trim()+"' ";
					}
					if(position!=null&position.trim().length()>0){
						sql += " and outsub.position_code = '"+position.trim()+"' ";
					}
					sql +=
						"GROUP BY wc.upper_category, "+
						"   wcr.category_code, "+
						"wc.name "+
						"UNION ALL "+
						"SELECT   wcr.category_code, wc.upper_category, "+
						"wc.name, "+
						"SUM (outsub.product_count) out_count, 0 out_money, "+
						"SUM (out_money) out_1002money "+
						"    FROM t_out_sub outsub LEFT OUTER JOIN t_out_head outhead "+
						"ON outsub.out_bill_id = outhead.ID "+
						"LEFT OUTER JOIN t_product wcr "+
						"ON UPPER (outsub.product_code) = "+
						"  UPPER (wcr.concentricity_code) "+
						"LEFT OUTER JOIN t_product_category wc "+
						"ON wcr.category_code = wc.code "+
						"   WHERE 1 = 1 "+
						"AND outhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
						"AND outhead.out_time >= '"+start+"' "+
						"AND outhead.out_time <= '"+end+"' "+
						"AND outhead.out_type = '2002' "+
						"AND outsub.status = '1' ";
					if(balance_mode!=null&balance_mode.trim().length()>0){
						sql += " and outsub.balance_mode = '"+balance_mode.trim()+"' ";
					}
					if(position!=null&position.trim().length()>0){
						sql += " and outsub.position_code = '"+position.trim()+"' ";
					}
					sql+=
						"GROUP BY wc.upper_category, "+
						"wcr.category_code, "+
						" wc.name) a2) aa1 "+
						" GROUP BY upper_category, category_code, name "+
						"  ORDER BY upper_category, category_code";
					List vec = new ArrayList();
					dbrs = DBEngine.doSelect(con, sql);
					rs = dbrs.getRs();
					vec.add(currentWarehouseCode);
					while (rs.next()) {
						totalSize++;
						String[] values = new String[15];
						values[0] = rs.getString("category_code");
						values[1] = rs.getString("init_count");
						values[2] = rs.getString("init_money");
						values[3] = rs.getString("in_count");
						values[4] = rs.getString("in_money");
						values[5] = rs.getString("in_1002money");
						values[6] = rs.getString("in_moneys");
						values[7] = rs.getString("out_count");
						values[8] = rs.getString("out_money");
						values[9] = rs.getString("out_2002money");
						values[10] = rs.getString("out_moneys");
						values[11] = rs.getString("final_count");
						values[12] = rs.getString("final_money");
						values[13] = rs.getString("upper_category")==null?"":rs.getString("upper_category");
						values[14] = rs.getString("name");
						vec.add(values);
					}
					fullList.add(vec);
				}
			} catch (Exception e2) {
				LogWriter.error(e2.getMessage());
				System.out.println(e2.getMessage());
			} finally {
				try {
					if (rs != null) {
						rs.close();
					}
					if (dbrs != null) {
						dbrs.clear();
					}
					if (con != null) {
						con.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (warehouesList == null) {
				isAvaliable = false;
			} else if (totalSize > 13000) {
				isAvaliable = false;
				isLager = true;
			} else {
				writeExcel_ReportPCMoneyInout(fullList,month,warehouseCode,fileName,start,end,request,response);
			}

		}

		else if("16".equals(title)){
			AirSortReportService airSortReportService=new AirSortReportService();
			try {
				Map airSortMap=airSortReportService.getAirSortReportMap(warehouseCode,start,end);
				writeExcel_ReportAirSort(airSortMap,warehouseName,month,"空调消耗报表",warehouseCode,fileName,start,end,request,response);
			} catch (GSException e) {
				e.printStackTrace();
			}
		}else if ("1".equals(title) || "9".equals(title)||"10".equals(title)||"18".equals(title)) {
			String masterStart = "";
			String masterEnd = "";
			String masterPart1Start = "";
			String masterPart1End = "";
			String in = "";
			String out = "";
			String newMonthStorage = "";
			Vector vec2 = new Vector();
			if(GSBaseConstants.PLANPRICE.equals("true")){
				title1 = warehouseName + "仓库产品进、销、存报表";
			}
			else{
				if("10".equals(title)){
					title1=warehouseName + "仓库产品买断进、销、存报表";
				}else if("18".equals(title)){
					title1=warehouseName + "仓库产品进、销、存供应商分类报表";

				}else{
					title1 = warehouseName + "仓库产品压库进、销、存报表";
				}
			}
			// 保存供应商列表集合
			Vector vec = null;
			/** 如果供应商名称参数为空 则从数据库中提取供应商 条件:以用户查询时间段为区间 */
			boolean needall = needAll.toLowerCase().equals("yes");// 是否是所有相关查询
			// 判断结算模式（1和10有区别）
			String balance_mode;
			if(title.equalsIgnoreCase("10")){
				balance_mode = "2";
			}else if(title.equals("18")){
				balance_mode = request.getParameter("balanceMode");
			}else{
				balance_mode = ConstDefine.getBalanceModeByFlag();
			}
			if(balance_mode.equals("0")){
				vec = detailqueryProviderGroupWithOutBalance_mode(warehouseCode, start, end, providerName,needall);
			}else{
				vec = detailqueryProviderGroup(warehouseCode, start, end, providerName,needall,balance_mode);
			}
			if (vec == null){
				vec = new Vector();
				isAvaliable = false;
			}
			int size = vec.size();
			/** 按供应商提取出入库明细 */
			int totalSize = 0;
			for (int i = 0; i < size; i++) {
				ProviderTemp pt = (ProviderTemp) vec.get(i);
				String name = pt.providerCode;
				Vector vec1 = new Vector();
				String all = null;
				if(balance_mode.equals("0")){
					masterStart =
						" select " +
						"aaa1.*," +
						"aaa2.CONCENTRICITY_CODE," +
						"aaa2.apep_code," +
						"aaa2.name,aaa2.spec," +
						"aaa2.model," +
						"aaa2.product_brand," +
						"aaa2.product_unit from ( ";
					if(needall) {
						masterEnd = " ) aaa1,t_product aaa2 where aaa1.pro_id = aaa2.id and (abs(aaa1.init_count) + abs(aaa1.in_count) + abs(aaa1.out_count) + abs(aaa1.final_count)) > 0";
					} else {
						masterEnd = " ) aaa1,t_product aaa2 where (abs(aaa1.in_count) + abs(aaa1.out_count)) > 0 and aaa1.pro_id = aaa2.id ";
					}
					masterPart1Start =
						" select "
						+ " aa1.product_id pro_id, "
						+ " aa1.product_price, "// /////////
						+ " sum(aa1.init_count) init_count, "
						+ " sum(aa1.init_money) init_money, "
						+ " sum(aa1.in_count) in_count, "
						+ " sum(aa1.in_money) in_money, "
						+ " sum(aa1.out_count) out_count, "
						+ " sum(aa1.out_money) out_money, "
						+ " sum(aa1.init_count) + sum(aa1.in_count) - sum(aa1.out_count) final_count, "
						+ " sum(aa1.init_money) + sum(aa1.in_money) - sum(aa1.out_money) final_money "
						+ " from ( ";
					masterPart1End =
						" ) aa1 group by aa1.product_id,aa1.product_price ";// //////////
					in =
						" select "
						+ " insub.product_id, "
						+ " insub.product_price, "// /////////
						+ " 0 init_count, "
						+ " 0 init_money, "
						+ " sum(insub.product_count) in_count, ";
					if(GSBaseConstants.PLANPRICE.equals("true")){
						in = in + " sum(insub.product_count * insub.actual_price) in_money, ";
					}
					else{
						in = in + " sum(insub.product_money) in_money, ";
					}

					in =  in + " 0 out_count, "
					+ " 0 out_money "
					+ " from "
					+ " t_in_sub insub "
					+ " left outer join t_in_head inhead on insub.in_bill_id = inhead.id "
					// + " left outer join t_product product on
					// insub.product_id = product.id " //改变供应商条件查询关联
					+ " where "
					+ " 1 = 1 "
					+ " and inhead.warehouse_code like '" + warehouseCode + "%' "
					+ " and inhead.in_time >= '" + start + "' "
					+ " and inhead.in_time <= '" + end + "' "
					+ " and insub.status = '1'"
					// + " and product.provider_code = '" + name + "' "
					+ " and inhead.provider_code = '" + name + "' "     // 改变供应商条件查询关联
					+ " group by " + " insub.product_id,insub.product_price ";// ////////////////
					out =
						" select "
						+ " outsub.product_id, "
						+ " outsub.product_price, "// /////////
						+ " 0 init_count, "
						+ " 0 init_money, "
						+ " 0 in_count, "
						+ " 0 in_money, "
						+ " sum(outsub.product_count) out_count, ";

					if(GSBaseConstants.PLANPRICE.equals("true")){
						out = out +" sum(outsub.product_count * outsub.actual_price) out_money " ;
					}else{
						out = out +" sum(outsub.product_money) out_money " ;
					}

					out = out + " from "
					+ " t_out_sub outsub "
					+ " left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "
					+ " left outer join t_product product on outsub.product_id = product.id "
					+ " where "
					+ " 1 = 1 "
					+ " and outhead.warehouse_code like '" + warehouseCode + "%' "
					+ " and outhead.out_time >= '" + start + "' "
					+ " and outhead.out_time <= '" + end + "' "
					+ " and outsub.status = '1'"
					// + " and product.provider_code = '" + name + "' "
					+ " and outsub.provider_code = '" + name + "' "     // 改变供应商条件查询关联
					+ " group by " + " outsub.product_id,outsub.product_price ";// /////////
					if("1".equals(title)||"10".equals(title)||"18".equals(title)){
						newMonthStorage =
							" select "+
							" sub_month.product_id, "+
							" sub_month.product_price, "+// /////////
							" sum(sub_month.son_in_count) - sum(sub_month.son_out_count) init_count, "+
							" sum(sub_month.son_in_money) - sum(sub_month.son_out_money) init_money, "+
							" 0 in_count, "+
							" 0 in_money, "+
							" 0 out_count, "+
							" 0 out_money  "+
							" from ( "+
							" select  "+
							" son_insub.product_id,  "+
							" son_insub.product_price, "+// /////////;
							" 0 son_init_count,  "+
							" 0 son_init_money,  "+
							" sum(son_insub.product_count) son_in_count,  ";

						if(GSBaseConstants.PLANPRICE.equals("true")){
							newMonthStorage = newMonthStorage +  " sum(son_insub.product_count * son_insub.actual_price) son_in_money,  ";
						}
						else{
							newMonthStorage = newMonthStorage +  " sum(son_insub.product_money) son_in_money,  ";
						}

						newMonthStorage = newMonthStorage +  " 0 son_out_count,  "+
						" 0 son_out_money  "+
						" from  "+
						" t_in_sub son_insub  "+
						" left outer join t_in_head son_inhead  "+
						" on son_insub.in_bill_id = son_inhead.id  "+
						// " left outer join t_product product "+
						// " on son_insub.product_id = product.id "+
						// //改变供应商条件查询关联
						" where  "+
						" 1 = 1  "+
						" and son_inhead.warehouse_code like '" + warehouseCode + "%' " +
						" and son_inhead.in_time < '"+before_end+"'  "+
						" and son_insub.status = '1'"+
						// " and product.provider_code = '"+name+"'
						// "+//改变供应商条件查询关联
						" and son_inhead.provider_code = '"+name+"'  "+    // 改变供应商条件查询关联
						" group by  "+
						" son_insub.product_id,son_insub.product_price "+// ////////////
						" union all "+
						" select  "+
						" son_outsub.product_id,  "+
						" son_outsub.product_price, "+// /////////
						" 0 son_init_count,  "+
						" 0 son_init_money,  "+
						" 0 son_in_count,  "+
						" 0 son_in_money,  "+
						" sum(son_outsub.product_count) son_out_count,  ";

						if(GSBaseConstants.PLANPRICE.equals("true")){
							newMonthStorage = newMonthStorage + " sum(son_outsub.product_count * son_outsub.actual_price) son_out_money  ";
						}
						else{
							newMonthStorage = newMonthStorage + " sum(son_outsub.product_money) son_out_money  ";
						}

						newMonthStorage = newMonthStorage + " from  "+
						" t_out_sub son_outsub  "+
						" left outer join t_out_head son_outhead  "+
						" on son_outsub.out_bill_id = son_outhead.id  "+
						// " left outer join t_product product "+
						// " on son_outsub.product_id = product.id
						// "+
						" where  "+
						" 1 = 1  "+
						" and son_outhead.warehouse_code like '" + warehouseCode + "%' " +
						" and son_outhead.out_time < '"+before_end+"'  "+
						" and son_outsub.status = '1'"+
						// " and product.provider_code = '"+name+"'
						// "+//改变供应商条件查询关联
						" and son_outsub.provider_code = '"+name+"'  "+// 改变供应商条件查询关联
						" group by  "+
						" son_outsub.product_id,son_outsub.product_price  "+// ////
						" ) sub_month  "+
						" group by sub_month.product_id,sub_month.product_price ";// //////////
					}
				}else{
					masterStart =
						" select " +
						"aaa1.*," +
						"aaa2.CONCENTRICITY_CODE," +
						"aaa2.apep_code," +
						"aaa2.name,aaa2.spec," +
						"aaa2.model," +
						"aaa2.product_brand," +
						"aaa2.product_unit from ( ";
					if(needall) {
						masterEnd = " ) aaa1,t_product aaa2 where aaa1.pro_id = aaa2.id and (abs(aaa1.init_count) + abs(aaa1.in_count) + abs(aaa1.out_count) + abs(aaa1.final_count)) > 0";
					} else {
						masterEnd = " ) aaa1,t_product aaa2 where (abs(aaa1.in_count) + abs(aaa1.out_count)) > 0 and aaa1.pro_id = aaa2.id ";
					}
					masterPart1Start =
						" select "
						+ " aa1.product_id pro_id, "
						+ " aa1.product_price, "// /////////
						+ " sum(aa1.init_count) init_count, "
						+ " sum(aa1.init_money) init_money, "
						+ " sum(aa1.in_count) in_count, "
						+ " sum(aa1.in_money) in_money, "
						+ " sum(aa1.out_count) out_count, "
						+ " sum(aa1.out_money) out_money, "
						+ " sum(aa1.init_count) + sum(aa1.in_count) - sum(aa1.out_count) final_count, "
						+ " sum(aa1.init_money) + sum(aa1.in_money) - sum(aa1.out_money) final_money "
						+ " from ( ";
					masterPart1End =
						" ) aa1 group by aa1.product_id,aa1.product_price ";// //////////
					in =
						" select "
						+ " insub.product_id, "
						+ " insub.product_price, "// /////////
						+ " 0 init_count, "
						+ " 0 init_money, "
						+ " sum(insub.product_count) in_count, ";
					if(GSBaseConstants.PLANPRICE.equals("true")){
						in = in + " sum(insub.product_count * insub.actual_price) in_money, ";
					}
					else{
						in = in + " sum(insub.product_money) in_money, ";
					}

					in =  in + " 0 out_count, "
					+ " 0 out_money "
					+ " from "
					+ " t_in_sub insub "
					+ " left outer join t_in_head inhead on insub.in_bill_id = inhead.id "
					// + " left outer join t_product product on
					// insub.product_id = product.id " //改变供应商条件查询关联
					+ " where "
					+ " 1 = 1 "
					+ " and inhead.warehouse_code like '" + warehouseCode + "%' "
					+ " and inhead.in_time >= '" + start + "' "
					+ " and inhead.in_time <= '" + end + "' "
					+ " and insub.balance_mode = '" + balance_mode+ "' and insub.status = '1'"
					// + " and product.provider_code = '" + name + "' "
					+ " and inhead.provider_code = '" + name + "' "     // 改变供应商条件查询关联
					+ " group by " + " insub.product_id,insub.product_price ";// ////////////////
					out =
						" select "
						+ " outsub.product_id, "
						+ " outsub.product_price, "// /////////
						+ " 0 init_count, "
						+ " 0 init_money, "
						+ " 0 in_count, "
						+ " 0 in_money, "
						+ " sum(outsub.product_count) out_count, ";

					if(GSBaseConstants.PLANPRICE.equals("true")){
						out = out +" sum(outsub.product_count * outsub.actual_price) out_money " ;
					}else{
						out = out +" sum(outsub.product_money) out_money " ;
					}

					out = out + " from "
					+ " t_out_sub outsub "
					+ " left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "
					+ " left outer join t_product product on outsub.product_id = product.id "
					+ " where "
					+ " 1 = 1 "
					+ " and outhead.warehouse_code like '" + warehouseCode + "%' "
					+ " and outhead.out_time >= '" + start + "' "
					+ " and outhead.out_time <= '" + end + "' "
					+ " and outsub.balance_mode = '" +balance_mode + "' and outsub.status = '1'"
					// + " and product.provider_code = '" + name + "' "
					+ " and outsub.provider_code = '" + name + "' "     // 改变供应商条件查询关联
					+ " group by " + " outsub.product_id,outsub.product_price ";// /////////
					if("1".equals(title)||"10".equals(title)||"18".equals(title)){
						newMonthStorage =
							" select "+
							" sub_month.product_id, "+
							" sub_month.product_price, "+// /////////
							" sum(sub_month.son_in_count) - sum(sub_month.son_out_count) init_count, "+
							" sum(sub_month.son_in_money) - sum(sub_month.son_out_money) init_money, "+
							" 0 in_count, "+
							" 0 in_money, "+
							" 0 out_count, "+
							" 0 out_money  "+
							" from ( "+
							" select  "+
							" son_insub.product_id,  "+
							" son_insub.product_price, "+// /////////;
							" 0 son_init_count,  "+
							" 0 son_init_money,  "+
							" sum(son_insub.product_count) son_in_count,  ";

						if(GSBaseConstants.PLANPRICE.equals("true")){
							newMonthStorage = newMonthStorage +  " sum(son_insub.product_count * son_insub.actual_price) son_in_money,  ";
						}
						else{
							newMonthStorage = newMonthStorage +  " sum(son_insub.product_money) son_in_money,  ";
						}

						newMonthStorage = newMonthStorage +  " 0 son_out_count,  "+
						" 0 son_out_money  "+
						" from  "+
						" t_in_sub son_insub  "+
						" left outer join t_in_head son_inhead  "+
						" on son_insub.in_bill_id = son_inhead.id  "+
						// " left outer join t_product product "+
						// " on son_insub.product_id = product.id "+
						// //改变供应商条件查询关联
						" where  "+
						" 1 = 1  "+
						" and son_inhead.warehouse_code like '" + warehouseCode + "%' " +
						" and son_inhead.in_time < '"+before_end+"'  "+
						" and son_insub.balance_mode = '" +balance_mode + "'  "+
						" and son_insub.status = '1'"+
						// " and product.provider_code = '"+name+"'
						// "+//改变供应商条件查询关联
						" and son_inhead.provider_code = '"+name+"'  "+    // 改变供应商条件查询关联
						" group by  "+
						" son_insub.product_id,son_insub.product_price "+// ////////////
						" union all "+
						" select  "+
						" son_outsub.product_id,  "+
						" son_outsub.product_price, "+// /////////
						" 0 son_init_count,  "+
						" 0 son_init_money,  "+
						" 0 son_in_count,  "+
						" 0 son_in_money,  "+
						" sum(son_outsub.product_count) son_out_count,  ";

						if(GSBaseConstants.PLANPRICE.equals("true")){
							newMonthStorage = newMonthStorage + " sum(son_outsub.product_count * son_outsub.actual_price) son_out_money  ";
						}
						else{
							newMonthStorage = newMonthStorage + " sum(son_outsub.product_money) son_out_money  ";
						}

						newMonthStorage = newMonthStorage + " from  "+
						" t_out_sub son_outsub  "+
						" left outer join t_out_head son_outhead  "+
						" on son_outsub.out_bill_id = son_outhead.id  "+
						// " left outer join t_product product "+
						// " on son_outsub.product_id = product.id
						// "+
						" where  "+
						" 1 = 1  "+
						" and son_outhead.warehouse_code like '" + warehouseCode + "%' " +
						" and son_outhead.out_time < '"+before_end+"'  "+
						" and son_outsub.balance_mode = '" + balance_mode + "'  "+
						" and son_outsub.status = '1'"+
						// " and product.provider_code = '"+name+"'
						// "+//改变供应商条件查询关联
						" and son_outsub.provider_code = '"+name+"'  "+// 改变供应商条件查询关联
						" group by  "+
						" son_outsub.product_id,son_outsub.product_price  "+// ////
						" ) sub_month  "+
						" group by sub_month.product_id,sub_month.product_price ";// //////////
					}else{
					}
				}


				DBConnection con = null;
				DBResult dbrs = null;
				ResultSet rs = null;
				all = masterStart + masterPart1Start + newMonthStorage + " union all " + in + " union all " + out + masterPart1End + masterEnd;
				try {
					con = DBConnection.open(false);
					dbrs = DBEngine.doSelect(con, all);
					rs = dbrs.getRs();
					vec1.add(pt);
					while (rs.next()) {
						totalSize++;
						String[] values = new String[16];
						values[0] = rs.getString("concentricity_code");
						values[1] = rs.getString("init_count");
						values[2] = rs.getString("init_money");
						values[3] = rs.getString("in_count");
						values[4] = rs.getString("in_money");
						values[5] = rs.getString("out_count");
						values[6] = rs.getString("out_money");
						values[7] = rs.getString("final_count");
						values[8] = rs.getString("final_money");
						values[9] = rs.getString("apep_code");
						values[10] = rs.getString("name");
						values[11] = rs.getString("spec");
						values[12] = rs.getString("model");
						values[13] = rs.getString("product_brand");
						values[14] = rs.getString("product_unit");
						values[15] = rs.getString("product_price");
						vec1.add(values);
					}
					vec2.add(vec1);
				} catch (Exception e) {
					e.printStackTrace();
				} finally{
					try {
						if(rs != null) {
							rs.close();
						}
					} catch (SQLException e) {
						e.printStackTrace();
					}
					try {
						if(dbrs != null) {
							dbrs.clear();
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					try {
						if(con != null) {
							con.close();
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
			if (!isAvaliable) {
				isAvaliable = false;
			} else if (totalSize > 13000) {
				isAvaliable = false;
				isLager = true;
			} else {
				if("18".equals(title)){
					writeExcel_ReportYKProductAll(month, title, fileName, vec2, title1, start, end, warehouseCode, request, response);
				}else{
					writeExcel_ReportYKProduct(month, title, fileName, vec2, title1, start, end, warehouseCode, request, response);
				}
			}
		}
		/** 领用报表 */
		else if ("2".equals(title)) {
			String customerName = "";
			try {
				DBConnection con = null;
				con = DBConnection.open(false);
				customerName = Customer.fetchByCode(con, customerCode).getName();
				con.close();

				String date = ""; // 显示日期
				if ("1".equals(querytype)) {
					title1 = warehouseName + "仓库" + customerName + "公司领用月报";
					date = "统计月:" + start.substring(0, 7);
				} else if("2".equals(querytype)) {
					title1 = warehouseName + "仓库" + customerName + "公司领用日报";
					date = "统计日:" + start.substring(0, 10);
				} else if("3".equals(querytype)) {
					title1 = warehouseName + "仓库" + customerName + "公司领用月报明细";
					date = "统计月:" + start.substring(0, 7);
				}
				ObjectList list =null;
				   if("3".equals(querytype)){
					   list= detailqueryDetail(warehouseCode, customerCode, start, end);
				   }else{
					   list = detailquery2Group(warehouseCode, customerCode, start, end);
				   }
						
				ObjectList cList = detailquery2(warehouseCode, customerCode, start, end);
				
				if (list.size() == 0) {
					isAvaliable = false;
				} else if (list.size() > 13000) {
					isAvaliable = false;
					isLager = true;
				} else {
					if("3".equals(querytype)){
						writeExcel_ReportCustomerDetail(title, fileName, list, title1, date, request, response);
					}else{
						writeExcel_ReportCustomer(title, fileName, list, cList, title1, date, request, response);
					}
				}
			} catch (Exception e2) {
				System.out.println(e2.getMessage());
			}
		} else if ("3".equals(title) || "10".equals(title)) {
			try {
				GSAutoAuditongDateConfigurator.getInstance();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			String reportYKProductMonth = GSAutoAuditongDateConfigurator.getReportYKProductMonthEnd().equals("")?start:GSAutoAuditongDateConfigurator.getReportYKProductMonthEnd();
			int res = reportYKProductMonth.compareTo(start);
			if(res<=0){
				ReportYKProductMonth report = new ReportYKProductMonth();
				report.doReport(title1, warehouseName, reportYKProductMonth, warehouseCode, start, end, title, fileName, request, response, isAvaliable, isLager,reportYKProductMonth,querytype);
			}else{
				if(GSBaseConstants.PLANPRICE.equals("true")){
					title1 = warehouseName + "仓库产品进、销、存资金汇总月报";
				}
				else{
					title1 = warehouseName + "仓库压库产品进、销、存资金汇总月报";
				}
				// 期初分类查询入库查询不包括"申沃"产品分类部分
				String monthSotragePartIn1 = " select "
					+ " substr(category_code, 1, 1) || '0000' category_code, "
					+ " sum(product_count) init_count, "
					+ " sum(product_money) init_money "
					+ " from "
					+ " t_in_sub insub "
					+ " left outer join t_in_head inhead on insub.in_bill_id = inhead.id "
					+ " left outer join t_product product on insub.product_id = product.id "
					// + " left outer join t_warehouse_product wp on
					// init.product_id = wp.product_id and wp.warehouse_code =
					// init.warehouse_code and init.position_code =
					// wp.default_location_code "
					+ " where " + " 1 = 1 " + " and inhead.warehouse_code like '" + warehouseCode + "%' " + " and inhead.in_time < '"+ start +"' "
					+ " and product.category_code <> '90001' " + " and insub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and insub.status = '1'" + " group by " + " substr(category_code, 1, 1) ";

				// 期初分类查询入库查询只包括"申沃"产品分类部分
				String monthStoragePartIn2 = " select "
					+ " category_code, "
					+ " sum(product_count) init_count, "
					+ " sum(product_money) init_money "
					+ " from "
					+ " t_in_sub insub "
					+ " left outer join t_in_head inhead on insub.in_bill_id = inhead.id "
					+ " left outer join t_product product on insub.product_id = product.id "
					// + " left outer join t_warehouse_product wp on
					// init.product_id = wp.product_id and wp.warehouse_code =
					// init.warehouse_code and init.position_code =
					// wp.default_location_code "
					+ " where " + " 1 = 1 " + " and inhead.warehouse_code like '" + warehouseCode + "%' " + " and inhead.in_time < '" + start + "' "
					+ " and product.category_code = '90001' " + " and insub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and insub.status = '1'" + " group by " + " category_code ";

				// 期初分类查询出库查询不包括"申沃"产品分类部分
				String monthSotragePartOut1 = " select "
					+ " substr(category_code, 1, 1) || '0000' category_code, "
					+ " sum(product_count) * -1 init_count, "
					+ " sum(product_money) * -1 init_money "
					+ " from "
					+ " t_out_sub outsub "
					+ " left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "
					+ " left outer join t_product product on outsub.product_id = product.id "
					// + " left outer join t_warehouse_product wp on
					// init.product_id = wp.product_id and wp.warehouse_code =
					// init.warehouse_code and init.position_code =
					// wp.default_location_code "
					+ " where " + " 1 = 1 " + " and outhead.warehouse_code like '" + warehouseCode + "%' " + " and outhead.out_time < '"+ start +"' "
					+ " and product.category_code <> '90001' " + " and outsub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and outsub.status = '1'" + " group by " + " substr(category_code, 1, 1) ";

				// 期初分类查询出库查询只包括"申沃"产品分类部分
				String monthStoragePartOut2 = " select "
					+ " category_code, "
					+ " sum(product_count) * -1 init_count, "
					+ " sum(product_money) * -1 init_money "
					+ " from "
					+ " t_out_sub outsub "
					+ " left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "
					+ " left outer join t_product product on outsub.product_id = product.id "
					// + " left outer join t_warehouse_product wp on
					// init.product_id = wp.product_id and wp.warehouse_code =
					// init.warehouse_code and init.position_code =
					// wp.default_location_code "
					+ " where " + " 1 = 1 " + " and outhead.warehouse_code like '" + warehouseCode + "%' " + " and outhead.out_time < '" + start + "' "
					+ " and product.category_code = '90001' " + " and outsub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and outsub.status = '1'" + " group by " + " category_code ";


				// 入库查询子查询不包括"90001"部分
				String inPart1 = " select " + " substr(category_code, 1, 1) || '0000' category_code, " + " sum(insub.product_count) in_count, "
				+ " sum(insub.product_money) in_money " + " from " + " t_in_sub insub "
				+ " left outer join t_in_head inhead on insub.in_bill_id = inhead.id "
				+ " left outer join t_product product on insub.product_id = product.id " + " where " + " 1 = 1 " + " and inhead.warehouse_code like '" + warehouseCode + "%' " + " and inhead.in_time >= '" + start + "' " + " and inhead.in_time <= '" + end + "' "
				+ " and product.category_code <> '90001' " + " and insub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and insub.status = '1'" + " group by " + " substr(category_code, 1, 1) ";

				// 入库查询子查询只包括"90001"部分
				String inPart2 = " select " + " category_code, " + " sum(insub.product_count) in_count, " + " sum(insub.product_money) in_money " + " from "
				+ " t_in_sub insub " + " left outer join t_in_head inhead on insub.in_bill_id = inhead.id "
				+ " left outer join t_product product on insub.product_id = product.id " + " where " + " 1 = 1 " + " and inhead.warehouse_code like '" + warehouseCode + "%' " + " and inhead.in_time >= '" + start + "' " + " and inhead.in_time <= '" + end + "' "
				+ " and product.category_code = '90001' " + " and insub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and insub.status = '1'" + " group by " + " category_code ";


				// 出库查询子查询不包括90001部分
				String outPart1 = " select " + " substr(category_code, 1, 1) || '0000' category_code, " + " sum(outsub.product_count) out_count, "
				+ " sum(outsub.product_money) out_money " + " from " + " t_out_sub outsub "
				+ " left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "
				+ " left outer join t_product product on outsub.product_id = product.id " + " where " + " 1 = 1 " + " and outhead.warehouse_code like '" + warehouseCode + "%' " + " and outhead.out_time >= '" + start + "' " + " and outhead.out_time <= '" + end + "' "
				+ " and product.category_code <> '90001' " + " and outsub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and outsub.status = '1'" + " group by substr(category_code, 1, 1) ";

				// 出库查询子查询只包括90001部分
				String outPart2 = " select " + " category_code, " + " sum(outsub.product_count) out_count, " + " sum(outsub.product_money) out_money " + " from "
				+ " t_out_sub outsub " + " left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "
				+ " left outer join t_product product on outsub.product_id = product.id " + " where " + " 1 = 1 " + " and outhead.warehouse_code like '" + warehouseCode + "%' " + " and outhead.out_time >= '" + start + "' " + " and outhead.out_time <= '" + end + "' "
				+ " and product.category_code = '90001' " + " and outsub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and outsub.status = '1'" + " group by category_code ";

				// 合计期初数据
				String sql_a3 = "";
				if("3".equals(title)){
					sql_a3 = "select " +
					"a3.category_code, " +
					"sum(a3.init_count) init_count , " +
					"sum(a3.init_money) init_money, " +
					"0 in_count, " +
					"0 in_money, " +
					"0 out_count, " +
					"0 out_money " +
					"from( " +
					monthSotragePartIn1 + " union all " +
					monthStoragePartIn2 + " union all " +
					monthSotragePartOut1 + " union all " +
					monthStoragePartOut2 +
					" ) a3 group by a3.category_code ";
				}else{/*
				 * 注释的月结代码
				 */
				}
				String sql_a1 = "select a1.category_code, " +
				"0 init_count, " +
				"0 init_money, " +
				"a1.in_count, " +
				"a1.in_money, " +
				"0 out_count, " +
				"0 out_money " +
				"from( " +
				inPart1 + " union all" + inPart2 +
				") a1 ";

				String sql_a2 = "select a2.category_code, " +
				"0 init_count, " +
				"0 init_money, " +
				"0 in_count, " +
				"0 in_money, " +
				"a2.out_count, " +
				"a2.out_money " +
				"from( " +
				outPart1 + " union all " + outPart2 +
				" ) a2 ";


				String all = "select " +
				" aa1.category_code, " +
				" sum(aa1.init_count) init_count, " +
				" sum(aa1.init_money) init_money, " +
				" sum(aa1.in_count) in_count, " +
				" sum(aa1.in_money) in_money, " +
				" sum(aa1.out_count) out_count, " +
				" sum(aa1.out_money) out_money, " +
				" sum(aa1.init_count) + sum(aa1.in_count) - sum(aa1.out_count) final_count, " +
				" sum(aa1.init_money) + sum(aa1.in_money) - sum(aa1.out_money) final_money " +
				" from ( " +
				sql_a3 + " union all " + sql_a1 + " union all " + sql_a2 +
				") aa1 group by category_code order by category_code";

				Vector vec = new Vector();

				DBConnection con = null;
				DBResult dbrs = null;
				java.sql.ResultSet rs = null;
				try {
					con = DBConnection.open(false);
					dbrs = DBEngine.doSelect(con, all);
					rs = dbrs.getRs();
					while (rs.next()) {
						String[] values = new String[9];
						values[0] = rs.getString("category_code");
						values[1] = rs.getString("init_count");
						values[2] = rs.getString("init_money");
						values[3] = rs.getString("in_count");
						values[4] = rs.getString("in_money");
						values[5] = rs.getString("out_money");
						values[6] = rs.getString("out_money");
						values[7] = rs.getString("final_count");
						values[8] = rs.getString("final_money");
						vec.add(values);
					}
					String date = "";
					if(querytype.equals("1")){
						date = "统计月:" + start.substring(0, 7); // 显示日期
					}else{
						date = "统计月:" + start.substring(0, 10) + " 至 " + end.substring(0, 10); // 显示日期
					}
					if (vec.size() == 0) {
						isAvaliable = false;
					} else if (vec.size() > 13000) {
						isAvaliable = false;
						isLager = true;
					} else {
						writeExcel_ReportYKProductMonth(vec, warehouseCode, month, title, fileName, title1, date, request, response, start, end);
					}
				} catch (Exception e2) {
					System.out.println(e2.getMessage());
				} finally {
					try {
						if (rs != null) {
							rs.close();
						}
						if (dbrs != null) {
							dbrs.clear();
						}
						if (con != null) {
							con.close();
						}
					} catch (SQLException e) {

						e.printStackTrace();
					} catch (Exception e) {

						e.printStackTrace();
					}
				}
			}
		} else if ("4".equals(title)) {
			if(GSBaseConstants.PLANPRICE.equals("true")){
				title1 = warehouseName + "仓库产品应付款月报";
			}
			else{
				title1 = warehouseName + "仓库压库产品应付款月报";
			}
			try {
				ObjectList list = detailquery4Group(warehouseCode, start, end);
				ObjectList trueList = detailquery4true(warehouseCode, start, end);
				ObjectList falseList = detailquery4false(warehouseCode, start, end);

				String date = "统计月:" + start.substring(0, 7); // 显示日期

				if (list.size() == 0) {
					isAvaliable = false;
				} else if (list.size() > 13000) {
					isAvaliable = false;
					isLager = true;
				} else {
					writeExcel_ReportYKMoneyMonth(title, fileName, list, trueList, falseList, title1, date, request, response);
				}
			} catch (Exception e2) {
				System.out.println(e2.getMessage());
			}
		} else if ("5".equals(title) || "11".equals(title)) {
			if(GSBaseConstants.PLANPRICE.equals("true")){
				title1 = warehouseName + "仓库产品资金进出累计汇总(成本价)";
			}
			else{
				title1 = warehouseName + "仓库买断产品资金进出累计汇总(成本价)";
			}
			String masterStart =
				" select "
				+ " aa1.category_code, "
				+ " sum(aa1.init_count) init_count, "
				+ " sum(aa1.init_money) init_money, "
				+ " sum(aa1.in_count) in_count, "
				+ " sum(aa1.in_money) in_money, "
				+ " sum(aa1.in_1002money) in_1002money, "
				+ " sum(aa1.in_money) + sum(aa1.in_1002money) in_moneys, "
				+ " sum(aa1.out_count) out_count, "
				+ " sum(aa1.out_money) out_money, "
				+ " sum(aa1.out_2002money) out_2002money, "
				+ " sum(aa1.out_money) + sum(aa1.out_2002money) out_moneys,  "
				+ " sum(aa1.init_count) + sum(aa1.in_count) - sum(aa1.out_count) final_count, "
				+ " sum(aa1.init_money) + sum(aa1.in_money) + sum(aa1.in_1002money) - sum(aa1.out_money) - sum(aa1.out_2002money) final_money "
				+ " from( ";

			String masterEnd = " ) aa1 " + " group by category_code order by category_code ";

			String inStart =
				" select "
				+ " a1.category_code, "
				+ " 0 init_count, "
				+ " 0 init_money, "
				+ " a1.in_count, "
				+ " a1.in_money, "
				+ " a1.in_1002money, "
				+ " 0 out_count, "
				+ " 0 out_money, "
				+ " 0 out_2002money "
				+ " from( ";

			String inEnd = " ) a1 ";

			String inPart1 =
				" select "
				+ " substr(category_code, 1, 1) || '0000' category_code, "
				+ " sum(insub.product_count) in_count, "
				+ " sum(insub.product_money) in_money, "
				+ " 0 in_1002money "
				+ " from "
				+ " t_in_sub insub "
				+ " left outer join t_in_head inhead on insub.in_bill_id = inhead.id "
				+ " left outer join t_product product on insub.product_id = product.id "
				+ " where "
				+ " 1 = 1 "
				+ " and inhead.warehouse_code like '" + warehouseCode + "%' "
				+ " and inhead.in_time >= '" + start + "' "
				+ " and inhead.in_time <= '" + end + "' "
				+ " and product.category_code <> '90001' "
				+ " and insub.balance_mode = '2' and insub.status = '1'"
				+ " and inhead.in_type = '1001' "
				+ " group by "
				+ " substr(category_code, 1, 1) ";

			String inPart2 =
				" select "
				+ " category_code, "
				+ " sum(insub.product_count) in_count, "
				+ " sum(insub.product_money) in_money, "
				+ " 0 in_1002money "
				+ " from "
				+ " t_in_sub insub "
				+ " left outer join t_in_head inhead on insub.in_bill_id = inhead.id "
				+ " left outer join t_product product on insub.product_id = product.id "
				+ " where "
				+ " 1 = 1 "
				+ " and inhead.warehouse_code like '" + warehouseCode + "%' "
				+ " and inhead.in_time >= '" + start + "' "
				+ " and inhead.in_time <= '" + end + "' "
				+ " and product.category_code = '90001' "
				+ " and insub.balance_mode = '2' and insub.status = '1'"
				+ " and inhead.in_type = '1001' "
				+ " group by "
				+ " category_code ";

			String inPart3 =
				" select "
				+ " substr(category_code, 1, 1) || '0000' category_code, "
				+ " sum(insub.product_count) in_count, "
				+ " 0 in_money, "
				+ " sum(insub.product_money) in_1002money "
				+ " from "
				+ " t_in_sub insub "
				+ " left outer join t_in_head inhead on insub.in_bill_id = inhead.id "
				+ " left outer join t_product product on insub.product_id = product.id "
				+ " where "
				+ " 1 = 1 "
				+ " and inhead.warehouse_code like '" + warehouseCode + "%' "
				+ " and inhead.in_time >= '" + start + "' "
				+ " and inhead.in_time <= '" + end + "' "
				+ " and product.category_code <> '90001' "
				+ " and insub.balance_mode = '2' and insub.status = '1'"
				+ " and inhead.in_type = '1002' "
				+ " group by "
				+ " substr(category_code, 1, 1) ";

			String inPart4 =
				" select "
				+ " category_code, "
				+ " sum(insub.product_count) in_count, "
				+ " 0 in_money, "
				+ " sum(insub.product_money) in_1002money "
				+ " from "
				+ " t_in_sub insub "
				+ " left outer join t_in_head inhead on insub.in_bill_id = inhead.id "
				+ " left outer join t_product product on insub.product_id = product.id "
				+ "  where " + " 1 = 1 " + " and inhead.warehouse_code like '" + warehouseCode + "%' "
				+ " and inhead.in_time >= '" + start + "' "
				+ " and inhead.in_time <= '" + end + "' "
				+ " and product.category_code = '90001' "
				+ " and insub.balance_mode = '2' and insub.status = '1'"
				+ " and inhead.in_type = '1002' " + " group by "
				+ " category_code ";

			String outStart =
				" select "
				+ " a2.category_code, "
				+ " 0 init_count, "
				+ " 0 init_money, "
				+ " 0 in_count, "
				+ " 0 in_money, "
				+ " 0 in_1002money, "
				+ " a2.out_count, "
				+ " a2.out_money, "
				+ " a2.out_1002money "
				+ " from( ";

			String outEnd = " ) a2 ";

			String outPart1 =
				" select "
				+ " substr(category_code, 1, 1) || '0000' category_code, "
				+ " sum(outsub.product_count) out_count, "
				+ " sum(outsub.product_money) out_money, "
				+ " 0 out_1002money "
				+ " from "
				+ " t_out_sub outsub "
				+ " left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "
				+ " left outer join t_product product on outsub.product_id = product.id "
				+ " where "
				+ " 1 = 1 "
				+ " and outhead.warehouse_code like '" + warehouseCode + "%' "
				+ " and outhead.out_time >= '" + start + "' "
				+ " and outhead.out_time <= '" + end + "' "
				+ " and product.category_code <> '90001' "
				+ " and outsub.balance_mode = '2' and outsub.status = '1'"
				+ " and outhead.out_type = '2001' "
				+ " group by substr(category_code, 1, 1) ";

			String outPart2 =
				" select "
				+ " category_code, "
				+ " sum(outsub.product_count) out_count, "
				+ " sum(outsub.product_money) out_money, "
				+ " 0 out_1002money "
				+ " from "
				+ " t_out_sub outsub "
				+ " left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "
				+ " left outer join t_product product on outsub.product_id = product.id "
				+ " where "
				+ " 1 = 1 "
				+ " and outhead.warehouse_code like '" + warehouseCode + "%' "
				+ " and outhead.out_time >= '" + start + "' "
				+ " and outhead.out_time <= '" + end + "' "
				+ " and product.category_code = '90001' "
				+ " and outsub.balance_mode = '2' and outsub.status = '1'"
				+ " and outhead.out_type = '2001' "
				+ " group by category_code ";

			String outPart3 =
				" select "
				+ " substr(category_code, 1, 1) || '0000' category_code, "
				+ " sum(outsub.product_count) out_count, "
				+ " 0 out_money, "
				+ " sum(out_money) out_1002money "
				+ " from "
				+ " t_out_sub outsub "
				+ " left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "
				+ " left outer join t_product product on outsub.product_id = product.id "
				+ " where "
				+ " 1 = 1 "
				+ " and outhead.warehouse_code like '" + warehouseCode + "%' "
				+ " and outhead.out_time >= '" + start + "' "
				+ " and outhead.out_time <= '" + end + "' "
				+ " and product.category_code <> '90001' "
				+ " and outsub.balance_mode = '2' and outsub.status = '1'"
				+ " and outhead.out_type = '2002' "
				+ " group by substr(category_code, 1, 1) ";

			String outPart4 =
				" select "
				+ " category_code, "
				+ " sum(outsub.product_count) out_count, "
				+ " 0 out_money, "
				+ " sum(out_money) out_1002money "
				+ " from "
				+ " t_out_sub outsub "
				+ " left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "
				+ " left outer join t_product product on outsub.product_id = product.id "
				+ " where "
				+ " 1 = 1 "
				+ " and outhead.warehouse_code like '" + warehouseCode + "%' "
				+ " and outhead.out_time >= '" + start + "' "
				+ " and outhead.out_time <= '" + end + "' "
				+ " and product.category_code = '90001' "
				+ " and outsub.balance_mode = '2' and outsub.status = '1'"
				+ " and outhead.out_type = '2002' "
				+ " group by category_code ";
			String newMonthStorage = "";
			if("5".equals(title)){
				newMonthStorage =
					" select "+
					" a3.category_code, "+
					" sum(a3.in_count) - sum(a3.out_count) init_count, "+
					" sum(a3.in_money) + sum(a3.in_1002money) - sum(a3.out_money) - sum(a3.out_2002money)init_money, "+
					" 0 in_count, "+
					" 0 in_money, "+
					" 0 in_1002money, "+
					" 0 out_count, "+
					" 0 out_money, "+
					" 0 out_2002money "+
					" from (  "+
					" select "+
					" a11.category_code,  "+
					" 0 init_count,  "+
					" 0 init_money,  "+
					" a11.in_count,  "+
					" a11.in_money,  "+
					" a11.in_1002money, "+
					" 0 out_count,  "+
					" 0 out_money,  "+
					" 0 out_2002money  "+
					" from(  "+
					" select  "+
					" substr(category_code, 1, 1) || '0000' category_code,  "+
					" sum(insub.product_count) in_count,  "+
					" sum(insub.product_money) in_money,  "+
					" 0 in_1002money  "+
					" from  "+
					" t_in_sub insub  "+
					" left outer join t_in_head inhead on insub.in_bill_id = inhead.id  "+
					" left outer join t_product product on insub.product_id = product.id  "+
					" where  "+
					" 1 = 1 "+
					" and inhead.warehouse_code like '"+warehouseCode+"%' "+
					" and inhead.in_time < '"+before_end+"'  "+
					" and product.category_code <> '90001'  "+
					" and insub.balance_mode = '2'  and insub.status = '1'"+
					" group by  "+
					" substr(category_code, 1, 1)   "+
					" union all  "+
					" select  "+
					" category_code,  "+
					" sum(insub.product_count) in_count,  "+
					" sum(insub.product_money) in_money,  "+
					" 0 in_1002money  "+
					" from  "+
					" t_in_sub insub  "+
					" left outer join t_in_head inhead on insub.in_bill_id = inhead.id  "+
					" left outer join t_product product on insub.product_id = product.id  "+
					" where  "+
					" 1 = 1  "+
					" and inhead.warehouse_code like '"+warehouseCode+"%' "+
					" and inhead.in_time < '"+before_end+"' "+
					" and product.category_code = '90001'  "+
					" and insub.balance_mode = '2'  and insub.status = '1'"+
					" group by  "+
					" category_code "+
					" ) a11  "+
					" union all  "+
					" select  "+
					" a22.category_code,  "+
					" 0 init_count,  "+
					" 0 init_money,  "+
					" 0 in_count,  "+
					" 0 in_money,  "+
					" 0 in_1002money, "+
					" a22.out_count,  "+
					" a22.out_money,  "+
					" a22.out_1002money  "+
					" from(    "+
					" select  "+
					" substr(category_code, 1, 1) || '0000' category_code,  "+
					" sum(outsub.product_count) out_count,  "+
					" sum(outsub.product_money) out_money,  "+
					" 0 out_1002money  "+
					" from  "+
					" t_out_sub outsub  "+
					" left outer join t_out_head outhead on outsub.out_bill_id = outhead.id  "+
					" left outer join t_product product on outsub.product_id = product.id  "+
					" where  "+
					" 1 = 1  "+
					" and outhead.warehouse_code like '"+warehouseCode+"%' "+
					" and outhead.out_time < '"+before_end+"'  "+
					" and product.category_code <> '90001'  "+
					" and outsub.balance_mode = '2'  and outsub.status = '1'"+
					" group by substr(category_code, 1, 1)  "+
					" union all  "+
					" select  "+
					" category_code,  "+
					" sum(outsub.product_count) out_count,  "+
					" sum(outsub.product_money) out_money,  "+
					" 0 out_1002money  "+
					" from  "+
					" t_out_sub outsub  "+
					" left outer join t_out_head outhead on outsub.out_bill_id = outhead.id  "+
					" left outer join t_product product on outsub.product_id = product.id  "+
					" where  "+
					" 1 = 1  "+
					" and outhead.warehouse_code like '"+warehouseCode+"%' "+
					" and outhead.out_time < '"+before_end+"' "+
					" and product.category_code = '90001'  "+
					" and outsub.balance_mode = '2'  and outsub.status = '1'"+
					" group by category_code  "+
					" ) a22  "+
					" ) a3 group by category_code  ";
			}else{/*
			 * 注释的月结代码
			 */
			}
			String all = null;
			all = masterStart + newMonthStorage + " union all " + inStart
			+ inPart1 + "union all " + inPart2 + " union all " + inPart3 + " union all " + inPart4 + inEnd + " union all " + outStart + outPart1
			+ "union all " + outPart2 + " union all " + outPart3 + " union all " + outPart4 + outEnd + masterEnd;
			Vector vec = new Vector();
			DBConnection con = null;
			DBResult dbrs = null;
			java.sql.ResultSet rs = null;
			try {
				con = DBConnection.open(false);
				dbrs = DBEngine.doSelect(con, all);
				rs = dbrs.getRs();
				while (rs.next()) {
					String[] values = new String[13];
					values[0] = rs.getString("category_code");
					values[1] = rs.getString("init_count");
					values[2] = rs.getString("init_money");
					values[3] = rs.getString("in_count");
					values[4] = rs.getString("in_money");
					values[5] = rs.getString("in_1002money");
					values[6] = rs.getString("in_moneys");
					values[7] = rs.getString("out_count");
					values[8] = rs.getString("out_money");
					values[9] = rs.getString("out_2002money");
					values[10] = rs.getString("out_moneys");
					values[11] = rs.getString("final_count");
					values[12] = rs.getString("final_money");
					vec.add(values);
				}
				if (vec.size() == 0) {
					isAvaliable = false;
				} else if (vec.size() > 13000) {
					isAvaliable = false;
					isLager = true;
				} else {
					writeExcel_ReportMDMoneyInout(vec, month, warehouseCode, title, fileName, title1, start, end, request, response);
				}
			} catch (Exception e2) {
				System.out.println(e2.getMessage());
			} finally {
				try {
					if (rs != null) {
						rs.close();
					}
					if (dbrs != null) {
						dbrs.clear();
					}
					if (con != null) {
						con.close();
					}
				} catch (SQLException e) {

					e.printStackTrace();
				} catch (Exception e) {

					e.printStackTrace();
				}
			}
		} else if ("6".equals(title)) {
			title1 = "合并库收料清单";
			try {
				ObjectList list = detailquery6Group(warehouseCode, inCustomerName, getCustomers, start, end);
				ObjectList listAll = detailquery6All(warehouseCode, inCustomerName, getCustomers, start, end);

				if (list.size() == 0) {
					isAvaliable = false;
				} else if (list.size() > 13000) {
					isAvaliable = false;
					isLager = true;

				} else {
					isAvaliable = true;
					writeExcel_ReportCustomerInList(warehouseCode, inCustomerName, getCustomers, title, fileName, list, listAll, title1, start, end, request,
							response);
				}
			} catch (Exception e) {

			}
		}else if("7".equals(title) || "12".equals(title)){
			if(GSBaseConstants.PLANPRICE.equals("true")){// 湖南巴士按实际价统计
				title1 = "产品分类月进出明细";
			}
			else{
				title1 = "压库产品分类月进出明细";
			}
			DBConnection con = null;
			DBResult dbrs = null;
			java.sql.ResultSet rs = null;
			Vector vec = null;
			try{
				// SQL语句总和
				String all = null;
				String masterStart = null;
				String masterEnd = null;
				String masterSubStart = null;
				String masterSubEnd = null;
				String monthStorage = null;
				String in = null;
				String out = null;

				masterStart =
					" select "+
					" aaa1.*, "+
					" aaa2.concentricity_code, "+
					" aaa2.apep_code, "+
					" aaa2.name, "+
					" aaa2.spec, "+
					" aaa2.model, "+
					" aaa2.product_brand, "+
					" aaa2.product_unit, "+
					" cate.name cate_name   "+
					" from(  ";
				masterSubStart =
					" select "+
					" aa1.category_code, "+
					" aa1.product_id, "+
					" aa1.product_price, "+// /////////////////
					" sum(aa1.init_count) init_count, "+
					" sum(aa1.init_money) init_money, "+
					" sum(aa1.in_count) in_count, "+
					" sum(aa1.in_money) in_money, "+
					" sum(aa1.out_count) out_count, "+
					" sum(aa1.out_money) out_money, "+
					" sum(aa1.init_count) + sum(aa1.in_count) - sum(aa1.out_count) final_count, "+
					" sum(aa1.init_money) + sum(aa1.in_money) - sum(aa1.out_money) final_money "+
					" from ( ";
				if("7".equals(title)){
					monthStorage =
						" select "+
						" a3.category_code, "+
						" a3.product_id, "+
						" a3.product_price, "+// /////////////////
						" sum(a3.init_count) init_count, "+
						" sum(a3.init_money) init_money, "+
						" 0 in_count, "+
						" 0 in_money, "+
						" 0 out_count, "+
						" 0 out_money "+
						" from( "+
						" select "+
						" substr(category_code, 1, 1) || '0000' category_code, "+
						" insub.product_id, "+
						" insub.product_price, "+// /////////////////
						" sum(product_count) init_count, "+
						" sum(product_money) init_money "+
						" from "+
						" t_in_sub insub "+
						" left outer join t_in_head inhead on insub.in_bill_id = inhead.id "+
						" left outer join t_product product on insub.product_id = product.id "+
						" where "+
						" 1 = 1 "+
						" and "+
						" inhead.warehouse_code like '"+warehouseCode+"%' "+
						" and "+
						" inhead.in_time < '"+start+"' "+
						" and "+
						" product.category_code <> '90001' "+
						" and "+
						" insub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and insub.status = '1'"+
						" group by "+
						" product_id,product_price,substr(category_code, 1, 1) "+   // //////////////////
						" union all "+
						" select "+
						" category_code, "+
						" insub.product_id, "+
						" insub.product_price, "+// /////////////////
						" sum(product_count) init_count, "+
						" sum(product_money) init_money "+
						" from "+
						" t_in_sub insub "+
						" left outer join t_in_head inhead on insub.in_bill_id = inhead.id "+
						" left outer join t_product product on insub.product_id = product.id "+
						" where "+
						" 1 = 1 "+
						" and "+
						" inhead.warehouse_code like '"+warehouseCode+"%' "+
						" and "+
						" inhead.in_time < '"+start+"' "+
						" and "+
						" product.category_code = '90001' "+
						" and "+
						" insub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and insub.status = '1'"+
						" group by "+
						" product_id,product_price,category_code "+// ////////////////
						" union all "+
						" select "+
						" substr(category_code, 1, 1) || '0000' category_code, "+
						" outsub.product_id, "+
						" outsub.product_price, "+// /////////////////
						" sum(product_count) * -1 init_count, "+
						" sum(product_money) * -1 init_money "+
						" from "+
						" t_out_sub outsub "+
						" left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "+
						" left outer join t_product product on outsub.product_id = product.id "+
						" where "+
						" 1 = 1 "+
						" and "+
						" outhead.warehouse_code like '"+warehouseCode+"%' "+
						" and "+
						" outhead.out_time < '"+start+"' "+
						" and "+
						" product.category_code <> '90001' "+
						" and "+
						" outsub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and outsub.status = '1'"+
						" group by "+
						" product_id,product_price,substr(category_code, 1, 1) "+  // //////////////////
						" union all "+
						" select "+
						" category_code, "+
						" outsub.product_id, "+
						" outsub.product_price, "+// /////////////////
						" sum(product_count) * -1 init_count, "+
						" sum(product_money) * -1 init_money "+
						" from "+
						" t_out_sub outsub "+
						" left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "+
						" left outer join t_product product on outsub.product_id = product.id "+
						" where "+
						" 1 = 1 "+
						" and "+
						" outhead.warehouse_code like '"+warehouseCode+"%' "+
						" and "+
						" outhead.out_time < '"+start+"' "+
						" and "+
						" product.category_code = '90001' "+
						" and "+
						" outsub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and outsub.status = '1'"+
						" group by "+
						" product_id,product_price,category_code "+// /////////////
						" ) a3 "+
						" group by "+
						" product_id,product_price,category_code ";// ////////////////////
				}else{/*
				 * 注释的月结代码
				 * /////////////////////在修改月结表字段前此段不可用!!!!!!!!!!!!!
				 * String lastBalanceMonth =
				 * MonthStorage.getLastBalanceMonth(warehouseCode);
				 * lastBalanceMonth = lastBalanceMonth.trim(); String
				 * _lastBalanceMonth = getEndBalanceTime(start);
				 * if(Integer.parseInt(lastBalanceMonth) >
				 * Integer.parseInt(_lastBalanceMonth)) lastBalanceMonth =
				 * _lastBalanceMonth; String lastBalanceTime =
				 * MonthStorage.getEndBalanceTime(lastBalanceMonth);
				 * monthStorage = " select "+ " a3.category_code, "+ "
				 * a3.product_id, "+ " a3.product_price,
				 * "+/////////////////// " sum(a3.init_count)
				 * init_count, "+ " sum(a3.init_money) init_money, "+ "
				 * 0 in_count, "+ " 0 in_money, "+ " 0 out_count, "+ " 0
				 * out_money "+ " from( "+
				 *  " select"+ " substr(pro.category_code,1,1) || '0000'
				 * category_code,"+ " ms.product_id,"+ "
				 * ms.product_price, "+/////////////////// "
				 * sum(ms.product_count) init_count,"+ "
				 * sum(ms.product_money) init_money"+ " from"+ "
				 * t_month_storage ms,t_product pro"+ " where"+ "
				 * ms.status = '1'"+ " and ms.product_id = pro.id"+ "
				 * and ms.warehouse_code = '"+warehouseCode+"'"+ " and
				 * ms.balance_mode = '1'"+ " and pro.category_code <>
				 * '90001'"+ " and ms.month = '"+lastBalanceMonth+"' "+ "
				 * group by
				 * ms.product_id,ms.product_price,substr(category_code,
				 * 1, 1)"+///////// " union all"+ " select"+ "
				 * pro.category_code,"+ " ms.product_id,"+ "
				 * ms.product_price, "+/////////////////// "
				 * sum(ms.product_count) init_count,"+ "
				 * sum(ms.product_money) init_money"+ " from"+ "
				 * t_month_storage ms,t_product pro"+ " where"+ "
				 * ms.status = '1'"+ " and ms.product_id = pro.id"+ "
				 * and ms.warehouse_code = '"+warehouseCode+"'"+ " and
				 * ms.balance_mode = '1'"+ " and pro.category_code =
				 * '90001'"+ " and ms.month = '"+lastBalanceMonth+"' "+ "
				 * group by
				 * ms.product_id,ms.product_price,pro.category_code"+/////////////
				 *  " union all"+
				 *  " select "+ " substr(category_code, 1, 1) || '0000'
				 * category_code, "+ " insub.product_id, "+ "
				 * insub.product_price, "+/////////////////// "
				 * sum(product_count) init_count, "+ "
				 * sum(product_money) init_money "+ " from "+ " t_in_sub
				 * insub "+ " left outer join t_in_head inhead on
				 * insub.in_bill_id = inhead.id "+ " left outer join
				 * t_product product on insub.product_id = product.id "+ "
				 * where "+ " 1 = 1 "+ " and "+ " inhead.warehouse_code =
				 * '"+warehouseCode+"' "+ " and "+ " inhead.in_time <
				 * '"+start+"' "+ " and "+ " inhead.in_time >
				 * '"+lastBalanceTime+"' "+ " and "+ "
				 * product.category_code <> '90001' "+ " and "+ "
				 * insub.balance_mode = '1' and insub.status = '1'"+ "
				 * group by "+ "
				 * product_id,product_price,substr(category_code, 1, 1) "+
				 * //////////////////// " union all "+ " select "+ "
				 * category_code, "+ " insub.product_id, "+ "
				 * insub.product_price, "+/////////////////// "
				 * sum(product_count) init_count, "+ "
				 * sum(product_money) init_money "+ " from "+ " t_in_sub
				 * insub "+ " left outer join t_in_head inhead on
				 * insub.in_bill_id = inhead.id "+ " left outer join
				 * t_product product on insub.product_id = product.id "+ "
				 * where "+ " 1 = 1 "+ " and "+ " inhead.warehouse_code =
				 * '"+warehouseCode+"' "+ " and "+ " inhead.in_time <
				 * '"+start+"' "+ " and "+ " inhead.in_time >
				 * '"+lastBalanceTime+"' "+ " and "+ "
				 * product.category_code = '90001' "+ " and "+ "
				 * insub.balance_mode = '1' and insub.status = '1'"+ "
				 * group by "+ " product_id,product_price,category_code
				 * "+////////////////// " union all "+ " select "+ "
				 * substr(category_code, 1, 1) || '0000' category_code, "+ "
				 * outsub.product_id, "+ " outsub.product_price,
				 * "+/////////////////// " sum(product_count) * -1
				 * init_count, "+ " sum(product_money) * -1 init_money "+ "
				 * from "+ " t_out_sub outsub "+ " left outer join
				 * t_out_head outhead on outsub.out_bill_id = outhead.id "+ "
				 * left outer join t_product product on
				 * outsub.product_id = product.id "+ " where "+ " 1 = 1 "+ "
				 * and "+ " outhead.warehouse_code = '"+warehouseCode+"' "+ "
				 * and "+ " outhead.out_time < '"+start+"' "+ " and "+ "
				 * outhead.out_time > '"+lastBalanceTime+"' "+ " and "+ "
				 * product.category_code <> '90001' "+ " and "+ "
				 * outsub.balance_mode = '1' and outsub.status = '1'"+ "
				 * group by "+ "
				 * product_id,product_price,substr(category_code, 1, 1) "+
				 * //////////////////// " union all "+ " select "+ "
				 * category_code, "+ " outsub.product_id, "+ "
				 * outsub.product_price, "+/////////////////// "
				 * sum(product_count) * -1 init_count, "+ "
				 * sum(product_money) * -1 init_money "+ " from "+ "
				 * t_out_sub outsub "+ " left outer join t_out_head
				 * outhead on outsub.out_bill_id = outhead.id "+ " left
				 * outer join t_product product on outsub.product_id =
				 * product.id "+ " where "+ " 1 = 1 "+ " and "+ "
				 * outhead.warehouse_code = '"+warehouseCode+"' "+ " and "+ "
				 * outhead.out_time < '"+start+"' "+ " and "+ "
				 * outhead.out_time > '"+lastBalanceTime+"' "+ " and "+ "
				 * product.category_code = '90001' "+ " and "+ "
				 * outsub.balance_mode = '1' and outsub.status = '1'"+ "
				 * group by "+ " product_id,product_price,category_code
				 * "+/////////////// " ) a3 "+ " group by "+ "
				 * product_id,product_price,category_code
				 * ";//////////////////////
				 */}
				in =
					" select "+
					" a1.category_code, "+
					" a1.product_id, "+
					" a1.product_price, "+// /////////////////
					" 0 init_count, "+
					" 0 init_money, "+
					" a1.in_count, "+
					" a1.in_money, "+
					" 0 out_count, "+
					" 0 out_money "+
					" from( "+
					" select "+
					" substr(category_code, 1, 1) || '0000' category_code, "+
					" insub.product_id, "+
					" insub.product_price, "+// /////////////////
					" sum(insub.product_count) in_count, "+
					" sum(insub.product_money) in_money "+
					" from "+
					" t_in_sub insub "+
					" left outer join t_in_head inhead on insub.in_bill_id = inhead.id "+
					" left outer join t_product product on insub.product_id = product.id "+
					" where "+
					" 1 = 1 "+
					" and "+
					" inhead.warehouse_code like '"+warehouseCode+"%' "+
					" and "+
					" inhead.in_time >= '"+start+"' "+
					" and "+
					" inhead.in_time <= '"+end+"' "+
					" and "+
					" product.category_code <> '90001' "+
					" and "+
					" insub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and insub.status = '1'"+
					" group by "+
					" product_id,product_price,substr(category_code, 1, 1) "+    // ////////////////
					" union all "+
					" select "+
					" category_code, "+
					" insub.product_id, "+
					" insub.product_price, "+// /////////////////
					" sum(insub.product_count) in_count, "+
					" sum(insub.product_money) in_money "+
					" from "+
					" t_in_sub insub "+
					" left outer join t_in_head inhead on insub.in_bill_id = inhead.id "+
					" left outer join t_product product on insub.product_id = product.id "+
					" where "+
					" 1 = 1 "+
					" and "+
					" inhead.warehouse_code like '"+warehouseCode+"%' "+
					" and "+
					" inhead.in_time >= '"+start+"' "+
					" and "+
					" inhead.in_time <= '"+end+"' "+
					" and "+
					" product.category_code = '90001' "+
					" and insub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and insub.status = '1'"+
					" group by "+
					" product_id,product_price,category_code "+// //////////////////////
					" ) a1 ";
				out =
					" select "+
					" a2.category_code, "+
					" a2.product_id, "+
					" a2.product_price, "+// /////////////////
					" 0 init_count, "+
					" 0 init_money, "+
					" 0 in_count, "+
					" 0 in_money, "+
					" a2.out_count, "+
					" a2.out_money "+
					" from( "+
					" select "+
					" substr(category_code, 1, 1) || '0000' category_code, "+
					" outsub.product_id, "+
					" outsub.product_price, "+// /////////////////
					" sum(outsub.product_count) out_count, "+
					" sum(outsub.product_money) out_money "+
					" from "+
					" t_out_sub outsub "+
					" left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "+
					" left outer join t_product product on outsub.product_id = product.id "+
					" where "+
					" 1 = 1 "+
					" and "+
					" outhead.warehouse_code like '"+warehouseCode+"%' "+
					" and "+
					" outhead.out_time >= '"+start+"' "+
					" and "+
					" outhead.out_time <= '"+end+"' "+
					" and "+
					" product.category_code <> '90001' "+
					" and "+
					" outsub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and outsub.status = '1'"+
					" group by "+
					" product_id,product_price,substr(category_code, 1, 1) "+// ///////////
					" union all "+
					" select "+
					" category_code, "+
					" outsub.product_id, "+
					" outsub.product_price, "+// /////////////////
					" sum(outsub.product_count) out_count, "+
					" sum(outsub.product_money) out_money "+
					" from "+
					" t_out_sub outsub "+
					" left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "+
					" left outer join t_product product on outsub.product_id = product.id "+
					" where "+
					" 1 = 1 "+
					" and "+
					" outhead.warehouse_code like '"+warehouseCode+"%' "+
					" and "+
					" outhead.out_time >= '"+start+"' "+
					" and "+
					" outhead.out_time <= '"+end+"' "+
					" and "+
					" product.category_code = '90001' "+
					" and "+
					" outsub.balance_mode = '" + ConstDefine.getBalanceModeByFlag() + "' and outsub.status = '1'"+
					" group by "+
					" product_id,product_price,category_code "+// //////////////////
					" ) a2 ";
				masterSubEnd =  " ) aa1 group by product_id,product_price,category_code order by category_code ";
				masterEnd = " ) aaa1,t_product aaa2,t_product_category cate " +
				"where aaa1.product_id = aaa2.id and cate.code = aaa1.category_code " +
				"order by aaa1.category_code";
				all = masterStart + masterSubStart + monthStorage + " union all " + in + " union all " + out + masterSubEnd + masterEnd;
				con = DBConnection.open(false);
				dbrs = DBEngine.doSelect(con, all);
				rs = dbrs.getRs();
				vec = new Vector();
				// 获得所有的符合查询条件的结果(其中包括所有的类别)
				while (rs.next()) {
					Map map = new HashMap();
					map.put("CATEGORY_CODE",rs.getString("CATEGORY_CODE"));
					map.put("PRODUCT_ID",rs.getString("PRODUCT_ID"));
					map.put("PRODUCT_PRICE",rs.getString("PRODUCT_PRICE"));
					map.put("INIT_COUNT",rs.getString("INIT_COUNT"));
					map.put("INIT_MONEY",rs.getString("INIT_MONEY"));
					map.put("IN_COUNT",rs.getString("IN_COUNT"));
					map.put("IN_MONEY",rs.getString("IN_MONEY"));
					map.put("OUT_COUNT",rs.getString("OUT_COUNT"));
					map.put("OUT_MONEY",rs.getString("OUT_MONEY"));
					map.put("FINAL_COUNT",rs.getString("FINAL_COUNT"));
					map.put("FINAL_MONEY",rs.getString("FINAL_MONEY"));
					map.put("APEP_CODE",rs.getString("APEP_CODE"));
					map.put("NAME",rs.getString("NAME"));
					map.put("SPEC",rs.getString("SPEC"));
					map.put("MODEL",rs.getString("MODEL"));
					map.put("PRODUCT_BRAND",rs.getString("PRODUCT_BRAND"));
					map.put("PRODUCT_UNIT",rs.getString("PRODUCT_UNIT"));
					map.put("CONCENTRICITY_CODE",rs.getString("CONCENTRICITY_CODE"));
					map.put("CATE_NAME",rs.getString("CATE_NAME"));
					vec.add(map);
				}
				// EXCEL生成方法
				if (vec.size() == 0) {
					isAvaliable = false;
				} else if (vec.size() > 15000) {
					//					ReportExporterUtils.writeCSV_ReportSeventh(vec, warehouseCode, month, title,
					//							fileName, title1, request, response, start, end,
					//							con);
					isAvaliable = false;
					isLager = true;
				} else {
					writeExcel_ReportSeventh(vec, warehouseCode, month, title, fileName, title1,request, response, start, end,con);
				}
			}catch(Exception e){
				e.printStackTrace();
			}finally{
				try {
					if(rs != null) {
						rs.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				try {
					if(dbrs != null) {
						dbrs.clear();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				try {
					if(con != null) {
						con.close();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} else if("8".equals(title) || "13".equals(title)){
			boolean flag = true;
			List warehouesList = new ArrayList();
			String balance_mode = "";
			String position ="";
			if("13".equals(title)){
				flag = false;
				warehouesList = WarehouseCategory.getWarehouseCode(warehouseCode);
				balance_mode = request.getParameter("balanceMode");
				position = request.getParameter("positionCode");
			}else{
				warehouesList = WarehouseCategory.getWarehouseCode(warehouseCode);
				// warehouesList =
				// WarehouseCategory.getWarehouseCodeByParentCode(warehouseCode);
			}

			int size = 0;
			if(warehouesList != null && warehouesList.size() > 0) {
				size = warehouesList.size();
			}
			int totalSize = 0;
			DBConnection con = null;
			DBResult dbrs = null;
			java.sql.ResultSet rs = null;
			List fullList = new ArrayList();
			try{
				con = DBConnection.open(false);
				for (int i = 0; i < size; i++) {
					String[] currentWarehouseCode = (String[])warehouesList.get(i);
					String  supperWarehouseCode =  currentWarehouseCode[0].trim().length()>6? currentWarehouseCode[0].trim().substring(0, currentWarehouseCode[0].length()-2):currentWarehouseCode[0];

					//判断是否是共享数据的仓库编码
					GSAutoAuditongDateConfigurator.getInstance();
					if(!GSAutoAuditongDateConfigurator.isShareDatesWarehouses(supperWarehouseCode)){
						supperWarehouseCode = currentWarehouseCode[0];
					}

					String tSupperWarehouseCodeOfNoShareProductProperty = currentWarehouseCode[0].trim().length()>6? currentWarehouseCode[0].trim().substring(0, currentWarehouseCode[0].length()-2):currentWarehouseCode[0];;

					// 加入是否共享产品属性判断
					if(GSAutoAuditongDateConfigurator.isNoShareWarehouseProductDatesWarehouses(tSupperWarehouseCodeOfNoShareProductProperty)){
						tSupperWarehouseCodeOfNoShareProductProperty = currentWarehouseCode[0];
					}
					String masterstart =
						" select "+
						" aa1.category_code, "+
						" aa1.parent_category_code, "+
						" aa1.category_name, "+
						" sum(aa1.init_count) init_count, "+
						" sum(aa1.init_money) init_money, "+
						" sum(aa1.in_count) in_count, "+
						" sum(aa1.in_money) in_money, "+
						" sum(aa1.in_1002money) in_1002money, "+
						" sum(aa1.in_money) + sum(aa1.in_1002money) in_moneys, "+
						" sum(aa1.out_count) out_count, "+
						" sum(aa1.out_money) out_money, "+
						" sum(aa1.out_2002money) out_2002money, "+
						" sum(aa1.out_money) + sum(aa1.out_2002money) out_moneys, "+
						" sum(aa1.init_count) + sum(aa1.in_count) - sum(aa1.out_count) final_count, "+
						" sum(aa1.init_money) + sum(aa1.in_money) + sum(aa1.in_1002money) - sum(aa1.out_money) - sum(aa1.out_2002money) final_money "+
						" from( ";
					String monthstorage = "";
					if("8".equals(title)|| "13".equals(title)){
						monthstorage =
							" select "+
							" a.category_code, "+
							" a.parent_category_code, "+
							" a.category_name, "+
							" sum(a.in_count) - sum(a.out_count) init_count, "+
							" sum(a.in_money) + sum(a.in_1002money) - sum(a.out_money) - sum(a.out_2002money)init_money, "+
							" 0 in_count, "+
							" 0 in_money, "+
							" 0 in_1002money, "+
							" 0 out_count, "+
							" 0 out_money, "+
							" 0 out_2002money "+
							" from ( "+
							" select "+
							" wcr.category_code, "+
							" wc.parent_category_code, "+
							" wc.category_name, "+
							" 0 init_count, "+
							" 0 init_money, "+
							" sum(insub.product_count) in_count, "+
							" sum(insub.product_money) in_money, "+
							" 0 in_1002money, "+
							" 0 out_count, "+
							" 0 out_money, "+
							" 0 out_2002money "+
							" from "+
							" t_in_sub insub "+
							" left outer join t_in_head inhead on insub.in_bill_id = inhead.id "+
							" left outer join t_warehouse_category_relation wcr on upper(insub.product_code) = upper(wcr.product_code) "+
							" left outer join t_warehouse_category wc on wcr.category_code = wc.category_code "+
							" where "+
							" 1 = 1 "+
							" and "+
							" inhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
							" and "+
							" inhead.in_time < '"+start+"' ";
						if(flag){
							monthstorage = monthstorage+" and  insub.balance_mode = '2' ";

						}else{
							if(balance_mode!=null&balance_mode.trim().length()>0){
								monthstorage += " and insub.balance_mode = '"+balance_mode.trim()+"' ";
							}
							if(position!=null&position.trim().length()>0){
								monthstorage += " and insub.position_code = '"+position.trim()+"' ";
							}
						}
						monthstorage = monthstorage+
						" and "+
						" wc.warehouse_code like '"+supperWarehouseCode+"%' and insub.status = '1'"+
						" and wcr.warehouse_code like '"+tSupperWarehouseCodeOfNoShareProductProperty+"%' "+
						" group by "+
						" wc.parent_category_code,wcr.category_code,wc.category_name "+

						" union all "+

						" select "+
						" wcr.category_code, "+
						" wc.parent_category_code, "+
						" wc.category_name, "+
						" 0 init_count, "+
						" 0 init_money, "+
						" 0 in_count, "+
						" 0 in_money, "+
						" 0 in_1002money, "+
						" sum(outsub.product_count) out_count, "+
						" sum(outsub.product_money) out_money, "+
						" 0 out_1002money "+
						" from "+
						" t_out_sub outsub "+
						" left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "+
						" left outer join t_warehouse_category_relation wcr on upper(outsub.product_code) = upper(wcr.product_code) "+
						" left outer join t_warehouse_category wc on wcr.category_code = wc.category_code "+
						" where "+
						" 1 = 1 "+
						" and "+
						" outhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
						" and "+
						" outhead.out_time < '"+start+"' ";
						if(flag){
							monthstorage = monthstorage+" and outsub.balance_mode = '2' ";
						}else{
							if(balance_mode!=null&balance_mode.trim().length()>0){
								monthstorage += " and outsub.balance_mode = '"+balance_mode.trim()+"' ";
							}
							if(position!=null&position.trim().length()>0){
								monthstorage += " and outsub.position_code = '"+position.trim()+"' ";
							}
						}
						monthstorage = monthstorage+
						" and "+
						" wc.warehouse_code like '"+supperWarehouseCode+"%' and outsub.status = '1'"+
						" and wcr.warehouse_code like '"+tSupperWarehouseCodeOfNoShareProductProperty+"%' "+
						" group by "+
						" wc.parent_category_code,wcr.category_code,wc.category_name "+
						" ) a "+
						" group by parent_category_code,category_code,category_name ";
					}else{/*
					 * 注释的月结代码 String lastBalanceMonth =
					 * MonthStorage.getLastBalanceMonth(warehouseCode);
					 * lastBalanceMonth = lastBalanceMonth.trim();
					 * String _lastBalanceMonth =
					 * getEndBalanceTime(start);
					 * if(Integer.parseInt(lastBalanceMonth) >
					 * Integer.parseInt(_lastBalanceMonth))
					 * lastBalanceMonth = _lastBalanceMonth; String
					 * lastBalanceTime =
					 * MonthStorage.getEndBalanceTime(lastBalanceMonth);
					 * monthstorage = " select "+ " a.category_code, "+ "
					 * a.parent_category_code, "+ " a.category_name, "+ "
					 * sum(init_count) + sum(a.in_count) -
					 * sum(a.out_count) init_count, "+ " sum(init_money) +
					 * sum(a.in_money) + sum(a.in_1002money) -
					 * sum(a.out_money) - sum(a.out_2002money)
					 * init_money, "+ " 0 in_count, "+ " 0 in_money, "+ "
					 * 0 in_1002money, "+ " 0 out_count, "+ " 0
					 * out_money, "+ " 0 out_2002money "+ " from ( "+ "
					 * select "+ " wcr.category_code, "+ "
					 * wc.parent_category_code, "+ " wc.category_name, "+ "
					 * 0 init_count, "+ " 0 init_money, "+ "
					 * sum(insub.product_count) in_count, "+ "
					 * sum(insub.product_money) in_money, "+ " 0
					 * in_1002money, "+ " 0 out_count, "+ " 0 out_money, "+ "
					 * 0 out_2002money "+ " from "+ " t_in_sub insub "+ "
					 * left outer join t_in_head inhead on
					 * insub.in_bill_id = inhead.id "+ " left outer join
					 * t_warehouse_category_relation wcr on
					 * upper(insub.product_code) =
					 * upper(wcr.product_code) "+ " left outer join
					 * t_warehouse_category wc on wcr.category_code =
					 * wc.category_code "+ " where "+ " 1 = 1 "+ " and "+ "
					 * inhead.warehouse_code = '"+warehouseCode+"' "+ "
					 * and "+ " inhead.in_time < '"+start+"' "+ " and "+ "
					 * inhead.in_time > '"+lastBalanceTime+"' "+ " and "+ "
					 * insub.balance_mode = '2' "+ " and "+ "
					 * wc.warehouse_code = '"+warehouseCode+"' and
					 * insub.status = '1'"+ " group by "+ "
					 * wc.parent_category_code,wcr.category_code,wc.category_name "+
					 *  " union all "+
					 *  " select "+ " wcr.category_code, "+ "
					 * wc.parent_category_code, "+ " wc.category_name, "+ "
					 * 0 init_count, "+ " 0 init_money, "+ " 0 in_count, "+ "
					 * 0 in_money, "+ " 0 in_1002money, "+ "
					 * sum(outsub.product_count) out_count, "+ "
					 * sum(outsub.product_money) out_money, "+ " 0
					 * out_1002money "+ " from "+ " t_out_sub outsub "+ "
					 * left outer join t_out_head outhead on
					 * outsub.out_bill_id = outhead.id "+ " left outer
					 * join t_warehouse_category_relation wcr on
					 * upper(outsub.product_code) =
					 * upper(wcr.product_code) "+ " left outer join
					 * t_warehouse_category wc on wcr.category_code =
					 * wc.category_code "+ " where "+ " 1 = 1 "+ " and "+ "
					 * outhead.warehouse_code = '"+warehouseCode+"' "+ "
					 * and "+ " outhead.out_time < '"+start+"' "+ " and "+ "
					 * outhead.out_time > '"+lastBalanceTime+"' "+ " and "+ "
					 * outsub.balance_mode = '2' "+ " and "+ "
					 * wc.warehouse_code = '"+warehouseCode+"' and
					 * outsub.status = '1'"+ " group by "+ "
					 * wc.parent_category_code,wcr.category_code,wc.category_name "+
					 *  " union all "+
					 *  " select"+ " wcr.category_code,"+ "
					 * wc.parent_category_code,"+ " wc.category_name,"+ "
					 * sum(ms.product_count) init_count,"+ "
					 * sum(ms.product_money) init_money,"+ " 0
					 * in_count,"+ " 0 in_money,"+ " 0 in_1002money,"+ "
					 * 0 out_count,"+ " 0 out_money,"+ " 0
					 * out_2002money"+ " from"+ " t_month_storage ms,"+ "
					 * t_warehouse_category_relation wcr,"+ "
					 * t_warehouse_category wc"+ " where"+ "
					 * ms.warehouse_code = '"+warehouseCode+"'"+ " and
					 * ms.balance_mode = '2'"+ " and wc.warehouse_code =
					 * '"+warehouseCode+"'"+ " and
					 * upper(wcr.product_code) =
					 * upper(ms.product_code)"+ " and wcr.category_code =
					 * wc.category_code"+ " and ms.month =
					 * '"+lastBalanceMonth+"' "+ " group by
					 * wc.parent_category_code,wcr.category_code,wc.category_name"+ " )
					 * a "+ " group by
					 * parent_category_code,category_code,category_name ";
					 */
					}
					String instart =
						" select "+
						" a1.category_code, "+
						" a1.parent_category_code, "+
						" a1.category_name, "+
						" 0 init_count, "+
						" 0 init_money, "+
						" a1.in_count, "+
						" a1.in_money, "+
						" a1.in_1002money, "+
						" 0 out_count, "+
						" 0 out_money, "+
						" 0 out_2002money   "+
						" from( ";

					String inpart =
						" select "+
						" wcr.category_code, "+
						" wc.parent_category_code, "+
						" wc.category_name, "+
						" sum(insub.product_count) in_count, "+
						" sum(insub.product_money) in_money, "+
						" 0 in_1002money "+
						" from "+
						" t_in_sub insub "+
						" left outer join t_in_head inhead on insub.in_bill_id = inhead.id "+
						" left outer join t_warehouse_category_relation wcr on upper(insub.product_code) = upper(wcr.product_code) "+
						" left outer join t_warehouse_category wc on wcr.category_code = wc.category_code "+
						" where "+
						" 1 = 1 "+
						" and "+
						" inhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
						" and "+
						" inhead.in_time >= '"+start+"' "+
						" and "+
						" inhead.in_time <= '"+end+"' "+
						" and wcr.warehouse_code like '"+tSupperWarehouseCodeOfNoShareProductProperty+"%' "+
						" and "+
						" wc.warehouse_code like '"+supperWarehouseCode+"%' ";
					if(flag){
						inpart+=" and  insub.balance_mode = '2' ";
					}else{
						if(balance_mode!=null&balance_mode.trim().length()>0){
							inpart += " and insub.balance_mode = '"+balance_mode.trim()+"' ";
						}
						if(position!=null&position.trim().length()>0){
							inpart += " and insub.position_code = '"+position.trim()+"' ";
						}
					}

					inpart=inpart+
					" and "+
					" inhead.in_type = '1001' and insub.status = '1'"+
					" group by "+
					" wc.parent_category_code,wcr.category_code,wc.category_name "+

					" union "+

					" select "+
					" wcr.category_code, "+
					" wc.parent_category_code, "+
					" wc.category_name, "+
					" sum(insub.product_count) in_count,  0 in_money, "+
					" sum(insub.product_money) in_1002money "+
					" from "+
					" t_in_sub insub "+
					" left outer join t_in_head inhead on insub.in_bill_id = inhead.id "+
					" left outer join t_warehouse_category_relation wcr on upper(insub.product_code) = upper(wcr.product_code) "+
					" left outer join t_warehouse_category wc on wcr.category_code = wc.category_code "+
					" where "+
					" 1 = 1 "+
					" and "+
					" inhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
					" and "+
					" inhead.in_time >= '"+start+"' "+
					" and "+
					" inhead.in_time <= '"+end+"' "+
					" and wcr.warehouse_code like '"+tSupperWarehouseCodeOfNoShareProductProperty+"%' "+
					" and "+
					" wc.warehouse_code like '"+supperWarehouseCode+"%' ";
					if(flag){
						inpart = inpart+" and  insub.balance_mode = '2' ";
					}else{
						if(balance_mode!=null&balance_mode.trim().length()>0){
							inpart += " and insub.balance_mode = '"+balance_mode.trim()+"' ";
						}
						if(position!=null&position.trim().length()>0){
							inpart += " and insub.position_code = '"+position.trim()+"' ";
						}
					}
					inpart = inpart+
					" and "+
					" inhead.in_type = '1002' and insub.status = '1'"+
					" group by "+
					" wc.parent_category_code,wcr.category_code,wc.category_name ";


					String inend = " ) a1 ";


					String outstart =
						" select "+
						" a2.category_code, "+
						" a2.parent_category_code, "+
						" a2.category_name, "+
						" 0 init_count, "+
						" 0 init_money, "+
						" 0 in_count, "+
						" 0 in_money, "+
						" 0 in_1002money, "+
						" a2.out_count, "+
						" a2.out_money, "+
						" a2.out_1002money "+
						" from(  ";


					String outpart =
						" select "+
						" wcr.category_code, "+
						" wc.parent_category_code, "+
						" wc.category_name, "+
						" sum(outsub.product_count) out_count, "+
						" sum(outsub.product_money) out_money, "+
						" 0 out_1002money "+
						" from "+
						" t_out_sub outsub "+
						" left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "+
						" left outer join t_warehouse_category_relation wcr on upper(outsub.product_code) = upper(wcr.product_code) "+
						" left outer join t_warehouse_category wc on wcr.category_code = wc.category_code "+
						" where "+
						" 1 = 1 "+
						" and outhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
						" and outhead.out_time >= '"+start+"' "+
						" and outhead.out_time <= '"+end+"' "+
						" and wcr.warehouse_code like '"+tSupperWarehouseCodeOfNoShareProductProperty+"%' "+
						" and wc.warehouse_code like '"+supperWarehouseCode+"%' ";
					if(flag){
						outpart = outpart+" and outsub.balance_mode = '2' ";
					}else{
						if(balance_mode!=null&balance_mode.trim().length()>0){
							outpart += " and outsub.balance_mode = '"+balance_mode.trim()+"' ";
						}
						if(position!=null&position.trim().length()>0){
							outpart += " and outsub.position_code = '"+position.trim()+"' ";
						}
					}
					outpart = outpart+
					" and outhead.out_type = '2001' and outsub.status = '1'"+
					" group by "+
					" wc.parent_category_code,wcr.category_code,wc.category_name "+

					" union all "+

					" select "+
					" wcr.category_code, "+
					" wc.parent_category_code, "+
					" wc.category_name, "+
					" sum(outsub.product_count) out_count,  0 out_money, "+
					" sum(out_money) out_1002money "+
					" from "+
					" t_out_sub outsub "+
					" left outer join t_out_head outhead on outsub.out_bill_id = outhead.id "+
					" left outer join t_warehouse_category_relation wcr on upper(outsub.product_code) = upper(wcr.product_code) "+
					" left outer join t_warehouse_category wc on wcr.category_code = wc.category_code "+
					" where "+
					" 1 = 1 "+
					" and outhead.warehouse_code like '"+currentWarehouseCode[0]+"%' "+
					" and outhead.out_time >= '"+start+"' "+
					" and outhead.out_time <= '"+end+"' "+
					" and wcr.warehouse_code like '"+tSupperWarehouseCodeOfNoShareProductProperty+"%' "+
					" and wc.warehouse_code like '"+supperWarehouseCode+"%' ";
					if(flag){
						outpart = outpart+" and outsub.balance_mode = '2' ";
					}else{
						if(balance_mode!=null&balance_mode.trim().length()>0){
							outpart += " and outsub.balance_mode = '"+balance_mode.trim()+"' ";
						}
						if(position!=null&position.trim().length()>0){
							outpart += " and outsub.position_code = '"+position.trim()+"' ";
						}
					}
					outpart = outpart+
					" and outhead.out_type = '2002' and outsub.status = '1'"+
					" group by "+
					" wc.parent_category_code,wcr.category_code,wc.category_name ";


					String outend = " ) a2 ";
					String masterend = " ) aa1  group by parent_category_code,category_code,category_name order by parent_category_code,category_code ";

					String all = null;
					all = masterstart + monthstorage + " union all " + instart + inpart + inend  + " union all " +  outstart + outpart + outend + masterend;
					List vec = new ArrayList();
					dbrs = DBEngine.doSelect(con, all);
					rs = dbrs.getRs();
					vec.add(currentWarehouseCode);
					while (rs.next()) {
						totalSize++;
						String[] values = new String[15];
						values[0] = rs.getString("category_code");
						values[1] = rs.getString("init_count");
						values[2] = rs.getString("init_money");
						values[3] = rs.getString("in_count");
						values[4] = rs.getString("in_money");
						values[5] = rs.getString("in_1002money");
						values[6] = rs.getString("in_moneys");
						values[7] = rs.getString("out_count");
						values[8] = rs.getString("out_money");
						values[9] = rs.getString("out_2002money");
						values[10] = rs.getString("out_moneys");
						values[11] = rs.getString("final_count");
						values[12] = rs.getString("final_money");
						values[13] = rs.getString("parent_category_code");
						values[14] = rs.getString("category_name");
						vec.add(values);
					}
					fullList.add(vec);
				}
			} catch (Exception e2) {
				LogWriter.error(e2.getMessage());
				System.out.println(e2.getMessage());
			} finally {
				try {
					if (rs != null) {
						rs.close();
					}
					if (dbrs != null) {
						dbrs.clear();
					}
					if (con != null) {
						con.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (warehouesList == null) {
				isAvaliable = false;
			} else if (totalSize > 13000) {
				isAvaliable = false;
				isLager = true;
			} else {
				if(flag){
					writeExcel_ReportMDWCMoneyInout(fullList,month,warehouseCode,fileName,start,end,request,response);
				}else{
					writeExcel_ReportWCMoneyInout(fullList,month,warehouseCode,fileName,start,end,request,response);
				}

			}
		}else if("14".equals(title)){
			// 构建SQL语句
			String sql =
				" select"+
				" warehouse_code,"+
				" t_warehouse.name,"+
				" balance_mode,"+
				" sum(init_money) init_money,"+
				" sum(in_money) in_money,"+
				" sum(out_money) out_money,"+
				" sum(in_and_out_money) in_and_out_money,"+
				" sum(init_money) + sum(in_money) - sum(out_money) + sum(final_money) final_money,"+
				" sum(in_bill_count) in_bill_count,"+
				" sum(out_bill_count) out_bill_count,"+
				" sum(in_and_out_bill_count) in_and_out_bill_count"+
				" from ("+
				// 期初金额统计 开始
				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" sum(sub.product_money) init_money,"+
				" 0 in_money,"+
				" 0 out_money,"+
				" 0 in_and_out_money,"+
				" 0 final_money,"+
				" 0 in_bill_count,"+
				" 0 out_bill_count,"+
				" 0 in_and_out_bill_count"+
				" from"+
				" t_in_sub sub"+
				" left outer join t_in_head head"+
				" on sub.in_bill_code = head.in_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.in_time < '"+start+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+

				" union all"+

				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" sum(sub.product_money) * -1 init_money,"+
				" 0 in_money,"+
				" 0 out_money,"+
				" 0 in_and_out_money,"+
				" 0 final_money,"+
				" 0 in_bill_count,"+
				" 0 out_bill_count,"+
				" 0 in_and_out_bill_count"+
				" from"+
				" t_out_sub sub"+
				" left outer join t_out_head head"+
				" on sub.out_bill_code = head.out_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.out_time < '"+start+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+
				// 期初金额统计 结束
				" union all"+
				// 入库金额统计 开始
				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" 0 init_money,"+
				" sum(sub.product_money) in_money,"+
				" 0 out_money,"+
				" 0 in_and_out_money,"+
				" 0 final_money,"+
				" 0 in_bill_count,"+
				" 0 out_bill_count,"+
				" 0 in_and_out_bill_count"+
				" from"+
				" t_in_sub sub"+
				" left outer join t_in_head head"+
				" on sub.in_bill_code = head.in_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.in_time >= '"+start+"'"+
				" and head.in_time <= '"+end+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+
				// 入库金额统计 结束
				" union all"+
				// 出库金额统计 开始
				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" 0 init_money,"+
				" 0 in_money,"+
				" sum(sub.product_money) out_money,"+
				" 0 in_and_out_money,"+
				" 0 final_money,"+
				" 0 in_bill_count,"+
				" 0 out_bill_count,"+
				" 0 in_and_out_bill_count"+
				" from"+
				" t_out_sub sub"+
				" left outer join t_out_head head"+
				" on sub.out_bill_code = head.out_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.out_time >= '"+start+"'"+
				" and head.out_time <= '"+end+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+
				// 出库金额统计 结束
				" union all"+
				// 入出库金额合计统计 开始
				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" 0 init_money,"+
				" 0 in_money,"+
				" 0 out_money,"+
				" sum(sub.product_money) in_and_out_money,"+
				" 0 final_money,"+
				" 0 in_bill_count,"+
				" 0 out_bill_count,"+
				" 0 in_and_out_bill_count"+
				" from"+
				" t_in_sub sub"+
				" left outer join t_in_head head"+
				" on sub.in_bill_code = head.in_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.in_time >= '"+start+"'"+
				" and head.in_time <= '"+end+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+
				" union all"+
				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" 0 init_money,"+
				" 0 in_money,"+
				" 0 out_money,"+
				" sum(sub.product_money) in_and_out_money,"+
				" 0 final_money,"+
				" 0 in_bill_count,"+
				" 0 out_bill_count,"+
				" 0 in_and_out_bill_count"+
				" from"+
				" t_out_sub sub"+
				" left outer join t_out_head head"+
				" on sub.out_bill_code = head.out_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.out_time >= '"+start+"'"+
				" and head.out_time <= '"+end+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+
				// 入出库金额合计统计 结束
				" union all"+
				// 期末金额统计 结束
				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" 0 init_money,"+
				" 0 in_money,"+
				" 0 out_money,"+
				" 0 in_and_out_money,"+
				" sum(sub.product_money) final_money,"+
				" 0 in_bill_count,"+
				" 0 out_bill_count,"+
				" 0 in_and_out_bill_count"+
				" from"+
				" t_in_sub sub"+
				" left outer join t_in_head head"+
				" on sub.in_bill_code = head.in_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.in_time > '"+end+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+
				" union all"+
				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" 0 init_money,"+
				" 0 in_money,"+
				" 0 out_money,"+
				" 0 in_and_out_money,"+
				" sum(sub.product_money) * -1 final_money,"+
				" 0 in_bill_count,"+
				" 0 out_bill_count,"+
				" 0 in_and_out_bill_count"+
				" from"+
				" t_out_sub sub"+
				" left outer join t_out_head head"+
				" on sub.out_bill_code = head.out_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.out_time > '"+end+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+
				// 期末金额统计 开始
				" union all"+
				// 入库单据统计 开始
				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" 0 init_money,"+
				" 0 in_money,"+
				" 0 out_money,"+
				" 0 in_and_out_money,"+
				" 0 final_money,"+
				" count(head.in_bill_code) in_bill_count,"+
				" 0 out_bill_count,"+
				" 0 in_and_out_bill_count"+
				" from"+
				" t_in_sub sub"+
				" left outer join t_in_head head"+
				" on sub.in_bill_code = head.in_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.in_time >= '"+start+"'"+
				" and head.in_time <= '"+end+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+
				// 入库单据统计 结束
				" union all"+
				// 出库单据统计 开始
				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" 0 init_money,"+
				" 0 in_money,"+
				" 0 out_money,"+
				" 0 in_and_out_money,"+
				" 0 final_money,"+
				" 0 in_bill_count,"+
				" count(head.out_bill_code) out_bill_count,"+
				" 0 in_and_out_bill_count"+
				" from"+
				" t_out_sub sub"+
				" left outer join t_out_head head"+
				" on sub.out_bill_code = head.out_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.out_time >= '"+start+"'"+
				" and head.out_time <= '"+end+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+
				// 出库单据统计 结束
				" union all"+
				// 出入库单据合计统计 开始
				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" 0 init_money,"+
				" 0 in_money,"+
				" 0 out_money,"+
				" 0 in_and_out_money,"+
				" 0 final_money,"+
				" 0 in_bill_count,"+
				" 0 out_bill_count,"+
				" count(head.in_bill_code) in_and_out_bill_count"+
				" from"+
				" t_in_sub sub"+
				" left outer join t_in_head head"+
				" on sub.in_bill_code = head.in_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.in_time >= '"+start+"'"+
				" and head.in_time <= '"+end+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+
				" union all"+
				" select"+
				" head.warehouse_code warehouse_code,"+
				" sub.balance_mode balance_mode,"+
				" 0 init_money,"+
				" 0 in_money,"+
				" 0 out_money,"+
				" 0 in_and_out_money,"+
				" 0 final_money,"+
				" 0 in_bill_count,"+
				" 0 out_bill_count,"+
				" count(head.out_bill_code) in_and_out_bill_count"+
				" from"+
				" t_out_sub sub"+
				" left outer join t_out_head head"+
				" on sub.out_bill_code = head.out_bill_code"+
				" where"+
				" sub.status = 1"+
				" and head.out_time >= '"+start+"'"+
				" and head.out_time <= '"+end+"'"+
				" group by"+
				" head.warehouse_code,sub.balance_mode"+
				// 出入库单据合计统计 结束
				" ) report,t_warehouse"+
				" where"+
				" report.warehouse_code = t_warehouse.code"+
				" group by"+
				" report.warehouse_code,t_warehouse.name,report.balance_mode"+
				" order by"+
				" report.warehouse_code,report.balance_mode";
			// 查询数据库
			List list = new ArrayList();
			DBConnection con = null;
			DBResult dbrs = null;
			ResultSet rs = null;
			try {
				con = DBConnection.open(false);
				dbrs = DBEngine.doSelect(con, sql);
				rs = dbrs.getRs();
				while (rs.next()) {
					Map map = new HashMap();
					map.put("WAREHOUSE_CODE",rs.getString("WAREHOUSE_CODE"));
					map.put("NAME",rs.getString("NAME"));
					map.put("BALANCE_MODE",rs.getString("BALANCE_MODE"));
					map.put("INIT_MONEY",rs.getString("INIT_MONEY"));
					map.put("IN_MONEY",rs.getString("IN_MONEY"));
					map.put("OUT_MONEY",rs.getString("OUT_MONEY"));
					map.put("IN_AND_OUT_MONEY",rs.getString("IN_AND_OUT_MONEY"));
					map.put("FINAL_MONEY",rs.getString("FINAL_MONEY"));
					map.put("IN_BILL_COUNT",rs.getString("IN_BILL_COUNT"));
					map.put("OUT_BILL_COUNT",rs.getString("OUT_BILL_COUNT"));
					map.put("IN_AND_OUT_BILL_COUNT",rs.getString("IN_AND_OUT_BILL_COUNT"));
					list.add(map);
				}
				if (list.size() == 0) {
					isAvaliable = false;
				} else if (list.size() > 13000) {
					isAvaliable = false;
					isLager = true;
				} else {
					writeExcel(list, fileName, response,sYear,sMonth);
				}
			} catch (Exception e2) {
				System.out.println(e2.getMessage());
			} finally {
				try {
					if (rs != null) {
						rs.close();
					}
					if (dbrs != null) {
						dbrs.clear();
					}
					if (con != null) {
						con.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}else if("19".equals(title)){
			title1 = warehouseName + "应付款月报(供应商)";

			try {
				ObjectList list = detailquery20Group(warehouseCode, start, end); //所有供应商
				ObjectList trueList = detailquery16YKOut(warehouseCode, start, end); //压库的出库供应商的产品价格
				ObjectList falseList = detailquery16MDIn(warehouseCode, start, end); //买断的入库供应商的产品价格
				//TODO 王宗好逻辑
//				List bidListYK = new ArrayList();
//				List bidListMD = new ArrayList();
//				List typeName = new ArrayList();
//				GSAutoAuditongDateConfigurator.getInstance();
//				List types = new ArrayList();
//				//招标分类
//				String bids [] =GSAutoAuditongDateConfigurator.getBidForProvider(); 
//				 GSProductTypeManagerDao bd = new  GSProductTypeManagerDao();
//				if(bids!=null&&bids.length>0){					 
//					for(int i=0;i<bids.length;i++){
//					 ObjectList byk = detailquery16YKOutByProductBid(warehouseCode, start, end,bids[i]);
//					 ObjectList bmd = detailquery16MDInByProductBid(warehouseCode, start, end,bids[i]);	
//					 bidListYK.add(byk);
//					 bidListMD.add(bmd);
//					 GSProductTypeManagerBean pbd =bd.findByTypeCodeAndPUpperCode(bids[i], "2000");
//					 typeName.add(pbd.getType_name());
//					 types.add(bids[i]);
//					}
//				}
//				//区域分类
//				String productTypes [] =GSAutoAuditongDateConfigurator.getProductTypeForProvider(); 
//				if(productTypes!=null&&productTypes.length>0){
//					for(int j=0;j<productTypes.length;j++){
//						ObjectList tyk = detailquery16YKOutByProductType(warehouseCode, start, end,productTypes[j]);
//						ObjectList tmd = detailquery16MDInByProductType(warehouseCode, start, end,productTypes[j]);	
//						 bidListYK.add(tyk);
//						 bidListMD.add(tmd);
//						 GSProductTypeManagerBean pbd =bd.findByTypeCodeAndPUpperCode(productTypes[j], "1000");
//						 typeName.add(pbd.getType_name());
//						 types.add(productTypes[j]);
//					}
//				}

				ObjectList zxkDianPingtrueList = detailquery16YKOutByProductBidForGroupZxk(warehouseCode, start, end,"41","90226,90227");
				ObjectList zxkDianPingfalseList = detailquery16MDInByProductBidForGroupZxk(warehouseCode, start, end,"41","90226,90227");
				
				ObjectList trueListYou = detailquery16YKOutByProductBidForGroup(warehouseCode, start, end,"20,38");
				ObjectList falseListYou = detailquery16MDInByProductBidForGroup(warehouseCode, start, end,"20,38");

				ObjectList trueListLun = detailquery16YKOutByProductBidForGroup(warehouseCode, start, end,"17,37,98,101");
				ObjectList falseListLun = detailquery16MDInByProductBidForGroup(warehouseCode, start, end,"17,37,98,101");

				ObjectList trueListFour = detailquery16YKOutByProductType(warehouseCode, start, end,GSBaseConstants.PRODUCT_TYPE4);
				ObjectList falseListFour = detailquery16MDInByProductType(warehouseCode, start, end,GSBaseConstants.PRODUCT_TYPE4);
				
				ObjectList trueAir = detailquery16YKOutByProductBid(warehouseCode, start, end,"22,73");
				ObjectList falseAir = detailquery16MDInByProductBid(warehouseCode, start, end,"22,73");	
				
				ObjectList trueListBus = detailquery16YKOutByProductBid(warehouseCode, start, end,"102");
				ObjectList falseListBus = detailquery16MDInByProductBid(warehouseCode, start, end,"102");
				
				String date = "统计月:" + start.substring(0, 7); // 显示日期

				if (list.size() == 0) {
					isAvaliable = false;
				} else if (list.size() > 13000) {
					isAvaliable = false;
					isLager = true;
				} else {
					writeExcel_ReportProvider(title, fileName, list, trueList, falseList, title1, date, request, response,trueListFour,falseListFour,trueListYou,falseListYou,trueListLun,falseListLun,trueAir,falseAir,trueListBus,falseListBus,zxkDianPingtrueList,zxkDianPingfalseList);
				}
			} catch (Exception e2) {
				System.out.println(e2.getMessage());
			}
		}else if("20".equals(title)){
				//TODO
				title1 = warehouseName + "产品供应商营运公司应付月报";
			try {
				ObjectList warehouseList = Warehouse.fetchAllWarehouseCode( DBConnection.open(false),warehouseCode);
				
				ObjectList list = detailquery20Group(warehouseCode, start, end);
				Map reportMap = new HashMap();
				for (int i = 0; i < warehouseList.size(); i++) {
					Warehouse warehouse = (Warehouse) warehouseList.get(i);
					ObjectList trueList = detailquery20YKOut(warehouse.getCode(), start, end);
					ObjectList falseList = detailquery20MDIn(warehouse.getCode(), start, end);
					for (int j = 0; j < list.size(); j++) {
						UniversalRow row = (UniversalRow) list.get(j);
						double trueMoney = 0;
						String pName ="";
						String providerCode= "";
						double falseMoney =0;
						for (int x = 0; x < trueList.size(); x++) {
							UniversalRow rowTrue = (UniversalRow) trueList.get(x);
							if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
								trueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
								pName = rowTrue.getString("NAME");
								providerCode = rowTrue.getString("CODE");
							}
						}
						for (int k = 0; k < falseList.size(); k++) {
							UniversalRow rowFalse = (UniversalRow) falseList.get(k);
							if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
								falseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
								pName = rowFalse.getString("NAME");
								providerCode = rowFalse.getString("CODE");
							}
						}
						reportMap.put(row.getString("PROVIDER_CODE")+warehouse.getCode(), new Object[]{String.valueOf(trueMoney),String.valueOf(falseMoney),pName,providerCode});
					}
				}
				

				String date = "统计月:" + start.substring(0, 7); // 显示日期

				if (list.size() == 0) {
					isAvaliable = false;
				} else if (list.size() > 13000) {
					isAvaliable = false;
					isLager = true;
				} else {
					writeExcel_ReportProviderCustomer(title, fileName,warehouseList, list,reportMap , title1, date, request, response);
				}
			} catch (Exception e2) {
				System.out.println(e2.getMessage());
			}
		}
		// 封装数据并返回给客户端
		// 判断报表生成的结果
		if (!isAvaliable) {
			if (isLager) {
				request.getSession().setAttribute("MSG", "数据量过于巨大，请缩小查询值的范围");
			} else {
				request.getSession().setAttribute("MSG", "没有查到数据,请重新输入查询条件");
			}
			try {
				String path = "";
				if ("1".equals(title)) {
					path = "/system/report/ReportYKProduct.jsp";
				}else if ("2".equals(title)) {
					path = "/system/report/ReportCustomer.jsp";
				}else if ("3".equals(title)) {
					path = "/system/report/ReportYKProductMonth.jsp";
				}else if ("4".equals(title)) {
					path = "/system/report/ReportYKMoneyMonth.jsp";
				}else if ("5".equals(title)) {
					path = "/system/report/ReportMDMoneyInout.jsp";
				}else if ("6".equals(title)) {
					path = "/system/report/ReportCustomerInList.jsp";
				}else if ("7".equals(title)) {
					path = "/system/report/ReportYKProductMonthList.jsp";
				}else if ("8".equals(title)) {
					path = "/system/report/ReportMDWCMoneyInout.jsp";
				}else if ("9".equals(title)) {
					path = "/system/report/ReportYKProductNew.jsp";
				}else if ("10".equals(title)) {
					path = "/system/report/ReportYKProductMonthNew.jsp";
				}else if ("11".equals(title)) {
					path = "/system/report/ReportMDMoneyInoutNew.jsp";
				}else if ("12".equals(title)) {
					path = "/system/report/ReportYKProductMonthListNew.jsp";
				}else if ("13".equals(title)) {
					path = "/system/report/ReportMDWCMoneyInoutNew.jsp";
				}else if ("14".equals(title)) {
					path = "/system/report/ReportAllWarehouseMoneyMonthSum.jsp";
				}else if("16".equals(title)){
					path="/system/report/ReportAirProduct.jsp";
				}else if ("17".equals(title)) {
					path = "/system/report/ReportMDWCMoneyInoutNew.jsp";
				}else if ("18".equals(title)) {
					path = "/system/report/ReportProduct.jsp";
				}else if ("19".equals(title)) {
					path = "/system/report/ReportProvider.jsp";
				}else if ("20".equals(title)) {
					path = "/system/report/ReportProviderCustomer.jsp";
				}
				getServletConfig().getServletContext().getRequestDispatcher(path).forward(request, response);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		session.setAttribute(IS_REPORT_PROCESSING, Boolean.FALSE);
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
		doPost(request, response);
	}

	/**
	 * 报表2 领用报表明细
	 * 
	 * @param aList
	 * @param title
	 * @param start
	 * @param end
	 */
	private void writeExcel_ReportCustomerDetail(String title, String fileName, ObjectList detailList, String title1, String date,
			HttpServletRequest request, HttpServletResponse response) {
		ServletOutputStream out = null;
		try {
			HSSFWorkbook tWb = new HSSFWorkbook();
			HSSFSheet tSheet = tWb.createSheet();
			HSSFRow tRow = null;
			Region region = null;
			tSheet.setColumnWidth((short) 0, (short) (16 * 256));
			tSheet.setColumnWidth((short) 1, (short) (12 * 256));
			tSheet.setColumnWidth((short) 2, (short) (12 * 256));
			tSheet.setColumnWidth((short) 3, (short) (18 * 256));

			tWb.setSheetName(0, title, HSSFCell.ENCODING_UTF_16);

			HSSFFont font = tWb.createFont();
			font.setFontHeightInPoints((short) 9);
			font.setFontName("宋体");
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

			HSSFCellStyle cStyle = tWb.createCellStyle();
			cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			HSSFCellStyle cStyleM = tWb.createCellStyle();
			cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM.setFont(font);

			HSSFCellStyle cStyleM_R = tWb.createCellStyle();
			cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			cStyleM_R.setFont(font);

			// 标题行
			tRow = tSheet.createRow((short) 0);
			HSSFCell c0 = createCell(tWb, tRow, (short) 2, title1);
			c0.setCellStyle(cStyleM);
			// 日期行
			tRow = tSheet.createRow((short) 1);
			region = new Region(1, (short) 2, 1, (short) 3);
			tSheet.addMergedRegion(region);
			createCell(tWb, tRow, (short) 2, date, HSSFCellStyle.ALIGN_CENTER, false);

			
			double totalMoney = 0;
			short index = 1; // 当前所在行号
			double customerMoney = 0;
			double groupMoney = 0;
			double unitPrice = 0;
			int num = 0;
			String productName = "";
			String productCode = "";
			String spec = "";
			String model = "";
			String productBrand= "";
			String productUnit= "";
			String productCount= "";
			String code="";
			

			for (int i = 0; i < detailList.size(); i++) {
				UniversalRow row = (UniversalRow) detailList.get(i);
				// -----------------------
				// 统计领料单位出库总金额
				customerMoney = 0;
				unitPrice = 0;
				customerMoney += Double.parseDouble(row.getString("MONEY"));
				unitPrice += Double.parseDouble(row.getString("UNITPRICE"));
				productCode = row.getString("PRODUCTCODE");
				productName = row.getString("PRODUCTNAME");
				spec = row.getString("SPEC");
				model = row.getString("MODEL");
				productBrand = row.getString("PRODUCTBRAND");
				productUnit = row.getString("PRODUCTUNIT");
				productCount = row.getString("PRODUCTCOUNT");
				totalMoney += customerMoney;
				if(i==0||code.equals(row.getString("CODE"))){
				groupMoney += customerMoney;
				}
				// -----------------------
				
				if(i==0||!code.equals(row.getString("CODE"))){
					if(i!=0){
						tRow = tSheet.createRow((short) (index + 1));
						HSSFCell sp1 = tRow.createCell((short) 0);
						HSSFCell sp2 = tRow.createCell((short) 1);
						HSSFCell cell_1 = tRow.createCell((short) 8);
						HSSFCell cell_2 = tRow.createCell((short) 9);

						sp1.setCellStyle(cStyleM_R);
						sp2.setCellStyle(cStyleM_R);
						cell_1.setCellStyle(cStyleM_R);
						cell_2.setCellStyle(cStyleM_R);

						// HSSFCell tongjiCell = tRow.createCell((short)1);
						cell_1.setEncoding(HSSFCell.ENCODING_UTF_16);
						String viewValue = StringUtil.showPrice(String.valueOf(groupMoney));

						cell_1.setCellValue("班组合计:");
						cell_2.setCellValue(viewValue);
						index++;
					}
					
					tRow = tSheet.createRow((short) (index + 1));
					createCell(tWb, tRow, (short) 0, row.getString("NAME")).setCellStyle(cStyleM_R);
					createCell(tWb, tRow, (short) 1, "领料情况:").setCellStyle(cStyleM_R);		
					index++;
					
					// 表头行
					tRow = tSheet.createRow((short) (index + 1));

					HSSFCell c1 = createCell(tWb, tRow, (short) 0, "序号");
					HSSFCell c2 = createCell(tWb, tRow, (short) 1, "产品编码");
					HSSFCell c3 = createCell(tWb, tRow, (short) 2, "产品名称");
					HSSFCell c4 = createCell(tWb, tRow, (short) 3, "规格");
					HSSFCell c5 = createCell(tWb, tRow, (short) 4, "型号");
					HSSFCell c6 = createCell(tWb, tRow, (short) 5, "品牌");
					HSSFCell c7 = createCell(tWb, tRow, (short) 6, "单位");
					HSSFCell c8 = createCell(tWb, tRow, (short) 7, "单价");
					HSSFCell c9 = createCell(tWb, tRow, (short) 8, "领用数量");
					HSSFCell c10 = createCell(tWb, tRow, (short) 9, "领用金额");
					c1.setCellStyle(cStyleM_R);
					c2.setCellStyle(cStyleM_R);
					c3.setCellStyle(cStyleM_R);
					c4.setCellStyle(cStyleM_R);
					c5.setCellStyle(cStyleM_R);
					c6.setCellStyle(cStyleM_R);
					c7.setCellStyle(cStyleM_R);
					c8.setCellStyle(cStyleM_R);
					c9.setCellStyle(cStyleM_R);
					c10.setCellStyle(cStyleM_R);
					
					index++;
					groupMoney=customerMoney;
				}
				
				tRow = tSheet.createRow((short) (index + 1));

				createCell(tWb, tRow, (short) 0, String.valueOf(++num));
				createCell(tWb, tRow, (short) 1, productCode);
				createCell(tWb, tRow, (short) 2, productName);
				createCell(tWb, tRow, (short) 3, spec);
				createCell(tWb, tRow, (short) 4, model);
				createCell(tWb, tRow, (short) 5, productBrand);
				createCell(tWb, tRow, (short) 6, productUnit);
				createCell(tWb, tRow, (short) 7, StringUtil.showPrice(String.valueOf(unitPrice)));
				createCell(tWb, tRow, (short) 8, productCount);
				createCell(tWb, tRow, (short) 9, StringUtil.showPrice(String.valueOf(customerMoney)));
				
				index++;
				code=row.getString("CODE");
				row = null;
				
			}
			if (index > 2) {
				tRow = tSheet.createRow((short) (index + 1));
				HSSFCell sp11 = tRow.createCell((short) 0);
				HSSFCell sp22 = tRow.createCell((short) 1);
				HSSFCell cell_11 = tRow.createCell((short) 8);
				HSSFCell cell_22 = tRow.createCell((short) 9);

				sp11.setCellStyle(cStyleM_R);
				sp22.setCellStyle(cStyleM_R);
				cell_11.setCellStyle(cStyleM_R);
				cell_22.setCellStyle(cStyleM_R);

				// HSSFCell tongjiCell = tRow.createCell((short)1);
				cell_11.setEncoding(HSSFCell.ENCODING_UTF_16);
				String viewValue = StringUtil.showPrice(String.valueOf(groupMoney));

				cell_11.setCellValue("班组合计:");
				cell_22.setCellValue(viewValue);
				index++;
				// 創建最後一個統計行
				tRow = tSheet.createRow((short) (index + 1));
				HSSFCell sp1 = tRow.createCell((short) 0);
				HSSFCell sp2 = tRow.createCell((short) 1);
				HSSFCell cell_1 = tRow.createCell((short) 8);
				HSSFCell cell_2 = tRow.createCell((short) 9);

				sp1.setCellStyle(cStyleM_R);
				sp2.setCellStyle(cStyleM_R);
				cell_1.setCellStyle(cStyleM_R);
				cell_2.setCellStyle(cStyleM_R);

				// HSSFCell tongjiCell = tRow.createCell((short)1);
				cell_1.setEncoding(HSSFCell.ENCODING_UTF_16);
				viewValue = StringUtil.showPrice(String.valueOf(totalMoney));

				cell_1.setCellValue("合计:");
				cell_2.setCellValue(viewValue);
			}

			fileName = fileName + ".xls";
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();
			tWb.write(out);

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}
		}
	}
	
	/**
	 * 报表2 领用报表
	 * 
	 * @param aList
	 * @param title
	 * @param start
	 * @param end
	 */
	private void writeExcel_ReportCustomer(String title, String fileName, ObjectList aList, ObjectList aListAll, String title1, String date,
			HttpServletRequest request, HttpServletResponse response) {
		ServletOutputStream out = null;
		try {
			HSSFWorkbook tWb = new HSSFWorkbook();
			HSSFSheet tSheet = tWb.createSheet();
			HSSFRow tRow = null;
			Region region = null;
			tSheet.setColumnWidth((short) 0, (short) (16 * 256));
			tSheet.setColumnWidth((short) 1, (short) (12 * 256));
			tSheet.setColumnWidth((short) 2, (short) (12 * 256));
			tSheet.setColumnWidth((short) 3, (short) (18 * 256));

			tWb.setSheetName(0, title, HSSFCell.ENCODING_UTF_16);

			HSSFFont font = tWb.createFont();
			font.setFontHeightInPoints((short) 9);
			font.setFontName("宋体");
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

			HSSFCellStyle cStyle = tWb.createCellStyle();
			cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			HSSFCellStyle cStyleM = tWb.createCellStyle();
			cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM.setFont(font);

			HSSFCellStyle cStyleM_R = tWb.createCellStyle();
			cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			cStyleM_R.setFont(font);

			// 标题行
			tRow = tSheet.createRow((short) 0);
			HSSFCell c0 = createCell(tWb, tRow, (short) 2, title1);
			c0.setCellStyle(cStyleM);
			// 日期行
			tRow = tSheet.createRow((short) 1);
			region = new Region(1, (short) 2, 1, (short) 3);
			tSheet.addMergedRegion(region);
			createCell(tWb, tRow, (short) 2, date, HSSFCellStyle.ALIGN_CENTER, false);

			// 表头行
			tRow = tSheet.createRow((short) 2);

			HSSFCell c1 = createCell(tWb, tRow, (short) 0, "序号");
			HSSFCell c2 = createCell(tWb, tRow, (short) 1, "领料单位编码");
			HSSFCell c3 = createCell(tWb, tRow, (short) 2, "领料单位名称");
			HSSFCell c4 = createCell(tWb, tRow, (short) 3, "总金额");
			c1.setCellStyle(cStyleM_R);
			c2.setCellStyle(cStyleM_R);
			c3.setCellStyle(cStyleM_R);
			c4.setCellStyle(cStyleM_R);
			double totalMoney = 0;
			short index = 2; // 当前所在行号
			double customerMoney = 0;
			int num = 0;
			String customerName = "";
			String customerCode = "";

			for (int i = 0; i < aList.size(); i++) {
				UniversalRow row = (UniversalRow) aList.get(i);
				// -----------------------
				// 统计领料单位出库总金额
				customerMoney = 0;
				for (int j = 0; j < aListAll.size(); j++) {
					UniversalRow rowAll = (UniversalRow) aListAll.get(j);
					if (rowAll.getString("CODE").equals(row.getString("CC"))) {
						customerMoney += Double.parseDouble(rowAll.getString("MONEY"));
						customerName = rowAll.getString("NAME");
						customerCode = rowAll.getString("CODE");
					}

				}
				totalMoney += customerMoney;
				// -----------------------

				tRow = tSheet.createRow((short) (index + 1));

				createCell(tWb, tRow, (short) 0, String.valueOf(++num));
				createCell(tWb, tRow, (short) 1, customerCode);
				createCell(tWb, tRow, (short) 2, customerName);
				createCell(tWb, tRow, (short) 3, StringUtil.showPrice(String.valueOf(customerMoney)));

				index++;

				row = null;
			}
			if (index > 2) {
				// 創建最後一個統計行
				tRow = tSheet.createRow((short) (index + 1));
				HSSFCell sp1 = tRow.createCell((short) 0);
				HSSFCell sp2 = tRow.createCell((short) 1);
				HSSFCell cell_1 = tRow.createCell((short) 2);
				HSSFCell cell_2 = tRow.createCell((short) 3);

				sp1.setCellStyle(cStyleM_R);
				sp2.setCellStyle(cStyleM_R);
				cell_1.setCellStyle(cStyleM_R);
				cell_2.setCellStyle(cStyleM_R);

				// HSSFCell tongjiCell = tRow.createCell((short)1);
				cell_1.setEncoding(HSSFCell.ENCODING_UTF_16);
				String viewValue = StringUtil.showPrice(String.valueOf(totalMoney));

				cell_1.setCellValue("合计:");
				cell_2.setCellValue(viewValue);
			}

			fileName = fileName + ".xls";
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();
			tWb.write(out);

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}
		}
	}

	/**
	 * 报表3 压库产品进销存资金汇总月报
	 * 
	 * @param aList
	 * @param title
	 * @param start
	 * @param end
	 */
	private void writeExcel_ReportYKProductMonth(Vector vec, String warehouseCode, String month, String title, String fileName, String title1, String date,
			HttpServletRequest request, HttpServletResponse response, String start, String end) {
		ServletOutputStream out = null;
		try {
			HSSFWorkbook tWb = new HSSFWorkbook();
			HSSFSheet tSheet = tWb.createSheet();
			HSSFRow tRow = null;
			Region region = null;
			tSheet.setColumnWidth((short) 0, (short) (16 * 256));
			tSheet.setColumnWidth((short) 1, (short) (12 * 256));
			tSheet.setColumnWidth((short) 2, (short) (12 * 256));
			tSheet.setColumnWidth((short) 3, (short) (18 * 256));
			tSheet.setColumnWidth((short) 4, (short) (10 * 256));

			tWb.setSheetName(0, title, HSSFCell.ENCODING_UTF_16);

			HSSFFont font = tWb.createFont();
			font.setFontHeightInPoints((short) 9);
			font.setFontName("宋体");
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

			HSSFCellStyle cStyle = tWb.createCellStyle();
			cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			HSSFCellStyle cStyleM = tWb.createCellStyle();
			cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM.setFont(font);

			HSSFCellStyle cStyleM_R = tWb.createCellStyle();
			cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			cStyleM_R.setFont(font);

			// 标题行
			tRow = tSheet.createRow((short) 0);
			HSSFCell c0 = createCell(tWb, tRow, (short) 2, title1);
			c0.setCellStyle(cStyleM);
			// 日期行
			tRow = tSheet.createRow((short) 1);
			region = new Region(1, (short) 3, 1, (short) 4);
			tSheet.addMergedRegion(region);
			createCell(tWb, tRow, (short) 3, date, HSSFCellStyle.ALIGN_CENTER, false);

			// 表头行
			tRow = tSheet.createRow((short) 2);

			HSSFCell c1 = createCell(tWb, tRow, (short) 0, "产品类别");
			HSSFCell c2 = createCell(tWb, tRow, (short) 1, "期初金额");
			HSSFCell c3 = createCell(tWb, tRow, (short) 2, "入库金额");
			HSSFCell c4 = createCell(tWb, tRow, (short) 3, "出库金额");
			HSSFCell c5 = createCell(tWb, tRow, (short) 4, "期末金额");

			c1.setCellStyle(cStyleM_R);
			c2.setCellStyle(cStyleM_R);
			c3.setCellStyle(cStyleM_R);
			c4.setCellStyle(cStyleM_R);
			c5.setCellStyle(cStyleM_R);
			short index = 2; // 当前所在行号
			DBConnection con = null;
			con = DBConnection.open(false);
			double totalMonth = 0;
			double totalIn = 0;
			double totalOut = 0;
			double totalFinal = 0;
			for (int i = 0; i < vec.size(); i++) {
				String[] values = (String[]) vec.get(i);
				// 創建一行
				tRow = tSheet.createRow((short) (index + 1));
				String cateName = null;
				if (values[0].equals("000000")) {
					cateName = "未分类";
				} else {
					ProductCategory pc = ProductCategory.fetchByCode(con, values[0]);
					if (pc != null) {
						cateName = pc.getName();
					}
				}
				String monthStorageMoneyTemp = values[2];
				String inMoneyTemp = values[4];
				String outMoneyTemp = values[6];
				String finalMoneyTemp = values[8];
				createCell(tWb, tRow, (short) 0, cateName);
				createCell(tWb, tRow, (short) 1, StringUtil.showPrice(monthStorageMoneyTemp));
				createCell(tWb, tRow, (short) 2, StringUtil.showPrice(inMoneyTemp));
				createCell(tWb, tRow, (short) 3, StringUtil.showPrice(outMoneyTemp));
				createCell(tWb, tRow, (short) 4, StringUtil.showPrice(finalMoneyTemp));
				index++;
				totalMonth += Double.parseDouble(monthStorageMoneyTemp);
				totalIn += Double.parseDouble(inMoneyTemp);
				totalOut += Double.parseDouble(outMoneyTemp);
				totalFinal += Double.parseDouble(finalMoneyTemp);
			}
			// 总计行
			if (index > 2) {
				tRow = tSheet.createRow((short) (index + 2));
				HSSFCell zongjiCell = tRow.createCell((short) 0);
				HSSFCell cell_1 = tRow.createCell((short) 1);
				HSSFCell cell_2 = tRow.createCell((short) 2);
				HSSFCell cell_3 = tRow.createCell((short) 3);
				HSSFCell cell_4 = tRow.createCell((short) 4);
				zongjiCell.setCellStyle(cStyleM_R);
				cell_1.setCellStyle(cStyleM_R);
				cell_2.setCellStyle(cStyleM_R);
				cell_3.setCellStyle(cStyleM_R);
				cell_4.setCellStyle(cStyleM_R);
				zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);
				zongjiCell.setCellValue("合计：");
				cell_1.setCellValue(StringUtil.showPrice(String.valueOf(totalMonth)));
				cell_2.setCellValue(StringUtil.showPrice(String.valueOf(totalIn)));
				cell_3.setCellValue(StringUtil.showPrice(String.valueOf(totalOut)));
				cell_4.setCellValue(StringUtil.showPrice(String.valueOf(totalFinal)));
			}
			fileName = fileName + ".xls";
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();
			tWb.write(out);
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}
		}
	}

	/**
	 * 报表4 压库产品应付款月报
	 * 
	 * @param aList
	 * @param title
	 * @param start
	 * @param end
	 */
	private void writeExcel_ReportYKMoneyMonth(String title, String fileName, ObjectList aList, ObjectList aListTrue, ObjectList aListFalse, String title1,
			String date, HttpServletRequest request, HttpServletResponse response) {
		ServletOutputStream out = null;
		try {
			HSSFWorkbook tWb = new HSSFWorkbook();
			HSSFSheet tSheet = tWb.createSheet();
			HSSFRow tRow = null;
			Region region = null;
			tSheet.setColumnWidth((short) 0, (short) (16 * 256));
			tSheet.setColumnWidth((short) 1, (short) (12 * 256));
			tSheet.setColumnWidth((short) 2, (short) (12 * 256));

			tWb.setSheetName(0, title1, HSSFCell.ENCODING_UTF_16);

			HSSFFont font = tWb.createFont();
			font.setFontHeightInPoints((short) 9);
			font.setFontName("宋体");
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

			HSSFCellStyle cStyle = tWb.createCellStyle();
			cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			HSSFCellStyle cStyleM = tWb.createCellStyle();
			cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM.setFont(font);

			HSSFCellStyle cStyleM_R = tWb.createCellStyle();
			cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			cStyleM_R.setFont(font);

			// 标题行
			tRow = tSheet.createRow((short) 0);
			HSSFCell c0 = createCell(tWb, tRow, (short) 1, title1);
			c0.setCellStyle(cStyleM);
			// 日期行
			tRow = tSheet.createRow((short) 1);
			region = new Region(1, (short) 1, 1, (short) 2);
			tSheet.addMergedRegion(region);
			createCell(tWb, tRow, (short) 1, date, HSSFCellStyle.ALIGN_CENTER, false);

			// 表头行
			tRow = tSheet.createRow((short) 2);

			HSSFCell c1 = createCell(tWb, tRow, (short) 0, "供应商编码");
			HSSFCell c2 = createCell(tWb, tRow, (short) 1, "供应商名称");
			HSSFCell c3 = createCell(tWb, tRow, (short) 2, "出库金额");

			c1.setCellStyle(cStyleM_R);
			c2.setCellStyle(cStyleM_R);
			c3.setCellStyle(cStyleM_R);
			short index = 2; // 当前所在行号
			double trueMoney = 0;
			double falseMoney = 0;
			double totalTrueMoney = 0;
			double totalFalseMoney = 0;

			String providerName = "";
			String providerCode = "";
			for (int i = 0; i < aList.size(); i++) {

				// -----------------------
				// 统计产品出入库总数及总价

				UniversalRow row = (UniversalRow) aList.get(i);

				// DBConnection con = null;
				// con = DBConnection.open(false);
				// Provider pv = Provider.fetchByCode(con,
				// row.getString("PROVIDER_CODE"));
				if (aListTrue != null) {
					for (int j = 0; j < aListTrue.size(); j++) {
						UniversalRow rowTrue = (UniversalRow) aListTrue.get(j);
						if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							trueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
							providerName = rowTrue.getString("NAME");
							providerCode = rowTrue.getString("CODE");
						}
					}
				} else {
					trueMoney = 0;
					// providerName = pv.getName();
				}

				if (aListFalse != null) {
					for (int k = 0; k < aListFalse.size(); k++) {
						UniversalRow rowFalse = (UniversalRow) aListFalse.get(k);
						if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							falseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
							providerName = rowFalse.getString("NAME");
							providerCode = rowFalse.getString("CODE");
						}
					}
				} else {
					falseMoney = 0;
					// con.close();
					// -----------------------
				}

				// 創建一行
				tRow = tSheet.createRow((short) (index + 1));
				createCell(tWb, tRow, (short) 0, providerCode);
				createCell(tWb, tRow, (short) 1, providerName);
				createCell(tWb, tRow, (short) 2, StringUtil.showPrice(String.valueOf(trueMoney+falseMoney)));

				index++;

				totalTrueMoney += trueMoney;
				totalFalseMoney += falseMoney;
				providerName = "";
				providerCode = "";
				trueMoney = 0;
				falseMoney = 0;
			}

			// 总计行
			if (index > 2) {
				tRow = tSheet.createRow((short) (index + 2));
				HSSFCell zongjiCell = tRow.createCell((short) 0);
				HSSFCell cell_1 = tRow.createCell((short) 1);
				HSSFCell cell_2 = tRow.createCell((short) 2);

				zongjiCell.setCellStyle(cStyleM_R);
				cell_1.setCellStyle(cStyleM_R);
				cell_2.setCellStyle(cStyleM_R);

				zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);
				zongjiCell.setCellValue("合计:");
				cell_1.setCellValue("");
				cell_2.setCellValue(StringUtil.showPrice(String.valueOf(totalTrueMoney+totalFalseMoney)));
				// region = new Region(index+2,(short)0,index+2,(short)3);
				// tSheet.addMergedRegion(region);

			}

			fileName = fileName + ".xls";
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();
			tWb.write(out);

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}
		}
	}

	/**
	 * 报表5 买断产品资金进出累计汇总（成本价）
	 * 
	 * @param aList
	 * @param title
	 * @param start
	 * @param end
	 */
	private void writeExcel_ReportMDMoneyInout(Vector vec, String month, String warehouseCode, String title, String fileName, String title1, String start,
			String end, HttpServletRequest request, HttpServletResponse response) {
		DBConnection con = null;
		ServletOutputStream out = null;
		try {
			HSSFWorkbook tWb = new HSSFWorkbook();
			HSSFSheet tSheet = tWb.createSheet();
			HSSFRow tRow = null;
			Region region = null;
			tSheet.setColumnWidth((short) 0, (short) (16 * 256));
			tSheet.setColumnWidth((short) 1, (short) (12 * 256));
			tSheet.setColumnWidth((short) 2, (short) (12 * 256));
			tSheet.setColumnWidth((short) 3, (short) (18 * 256));
			tSheet.setColumnWidth((short) 4, (short) (10 * 256));
			tSheet.setColumnWidth((short) 5, (short) (10 * 256));
			tSheet.setColumnWidth((short) 6, (short) (10 * 256));
			tSheet.setColumnWidth((short) 7, (short) (10 * 256));
			tSheet.setColumnWidth((short) 8, (short) (12 * 256));
			tSheet.setColumnWidth((short) 9, (short) (14 * 256));
			tSheet.setColumnWidth((short) 10, (short) (14 * 256));
			tSheet.setColumnWidth((short) 11, (short) (14 * 256));
			tSheet.setColumnWidth((short) 12, (short) (14 * 256));
			tSheet.setColumnWidth((short) 13, (short) (14 * 256));

			tWb.setSheetName(0, title1, HSSFCell.ENCODING_UTF_16);

			HSSFFont font = tWb.createFont();
			font.setFontHeightInPoints((short) 9);
			font.setFontName("宋体");
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

			HSSFCellStyle cStyle = tWb.createCellStyle();
			cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			HSSFCellStyle cStyleM = tWb.createCellStyle();
			cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM.setFont(font);

			HSSFCellStyle cStyleM_R = tWb.createCellStyle();
			cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			cStyleM_R.setFont(font);

			// 标题行
			tRow = tSheet.createRow((short) 0);
			HSSFCell c0 = createCell(tWb, tRow, (short) 4, title1);
			c0.setCellStyle(cStyleM);
			// 日期行
			tRow = tSheet.createRow((short) 1);
			region = new Region(1, (short) 4, 1, (short) 8);
			tSheet.addMergedRegion(region);
			createCell(tWb, tRow, (short) 4, "统计日期:" + start + " 至 " + end, HSSFCellStyle.ALIGN_CENTER, false);

			// 表头行
			tRow = tSheet.createRow((short) 2);

			HSSFCell c1 = createCell(tWb, tRow, (short) 0, "产品类别");
			HSSFCell c2 = createCell(tWb, tRow, (short) 1, "期初金额");
			HSSFCell c3 = createCell(tWb, tRow, (short) 2, "购入");
			HSSFCell c4 = createCell(tWb, tRow, (short) 3, "盘盈");
			HSSFCell c5 = createCell(tWb, tRow, (short) 4, "入库合计");
			HSSFCell c6 = createCell(tWb, tRow, (short) 5, "领用");
			HSSFCell c7 = createCell(tWb, tRow, (short) 6, "盘亏");
			HSSFCell c8 = createCell(tWb, tRow, (short) 7, "出库合计");
			HSSFCell c9 = createCell(tWb, tRow, (short) 8, "结存");

			c1.setCellStyle(cStyleM_R);
			c2.setCellStyle(cStyleM_R);
			c3.setCellStyle(cStyleM_R);
			c4.setCellStyle(cStyleM_R);
			c5.setCellStyle(cStyleM_R);
			c6.setCellStyle(cStyleM_R);
			c7.setCellStyle(cStyleM_R);
			c8.setCellStyle(cStyleM_R);
			c9.setCellStyle(cStyleM_R);

			short index = 2; // 当前所在行号

			double productInMoney1 = 0;
			double productInMoney2 = 0;
			double productInMoney3 = 0;
			double productOutMoney1 = 0;
			double productOutMoney2 = 0;
			double productOutMoney3 = 0;
			double allMoney = 0;

			// 期初数据

			double monthMoney = 0;

			// 合计行信息
			double totalMonthMoney = 0;
			double totalInMoney1 = 0;
			double totalInMoney2 = 0;
			double totalAllInMoney = 0;
			double totalOutMoney1 = 0;
			double totalOutMoney2 = 0;
			double totalAllOutMoney = 0;
			double totalMoney = 0;

			con = DBConnection.open(false);
			
			String cateName = "";
			for (int i = 0; i < vec.size(); i++) {
				String[] values = (String[]) vec.get(i);
				monthMoney = Double.parseDouble(values[2]);
				productInMoney1 = Double.parseDouble(values[4]);
				productInMoney2 = Double.parseDouble(values[5]);
				productInMoney3 = Double.parseDouble(values[6]);
				productOutMoney1 = Double.parseDouble(values[8]);
				productOutMoney2 = Double.parseDouble(values[9]);
				productOutMoney3 = Double.parseDouble(values[10]);
				allMoney = Double.parseDouble(values[12]);
				if (values[0].equals("000000")) {
					cateName = "未分类";
				} else {
					ProductCategory pc = ProductCategory.fetchByCode(con, values[0]);
					if (pc != null) {
						cateName = pc.getName();
					}
				}
				tRow = tSheet.createRow((short) (index + 1));
				createCell(tWb, tRow, (short) 0, cateName);
				createCell(tWb, tRow, (short) 1, StringUtil.showPrice(String.valueOf(monthMoney)));
				createCell(tWb, tRow, (short) 2, StringUtil.showPrice(String.valueOf(productInMoney1)));
				createCell(tWb, tRow, (short) 3, StringUtil.showPrice(String.valueOf(productInMoney2)));
				createCell(tWb, tRow, (short) 4, StringUtil.showPrice(String.valueOf(productInMoney3)));
				createCell(tWb, tRow, (short) 5, StringUtil.showPrice(String.valueOf(productOutMoney1)));
				createCell(tWb, tRow, (short) 6, StringUtil.showPrice(String.valueOf(productOutMoney2)));
				createCell(tWb, tRow, (short) 7, StringUtil.showPrice(String.valueOf(productOutMoney3)));
				createCell(tWb, tRow, (short) 8, StringUtil.showPrice(String.valueOf(allMoney)));

				totalMonthMoney += monthMoney;
				totalInMoney1 += productInMoney1;
				totalInMoney2 += productInMoney2;
				totalAllInMoney += productInMoney3;
				totalOutMoney1 += productOutMoney1;
				totalOutMoney2 += productOutMoney2;
				totalAllOutMoney += productOutMoney3;
				totalMoney += allMoney;

				productInMoney1 = 0;
				productInMoney2 = 0;
				productOutMoney1 = 0;
				productOutMoney2 = 0;
				allMoney = 0;
				monthMoney = 0;
				allMoney = 0;
				index++;
			}
			index++;

			// 总计行
			if (index > 2) {
				tRow = tSheet.createRow((short) (index + 2));
				HSSFCell zongjiCell = tRow.createCell((short) 0);
				HSSFCell cell_1 = tRow.createCell((short) 1);
				HSSFCell cell_2 = tRow.createCell((short) 2);
				HSSFCell cell_3 = tRow.createCell((short) 3);
				HSSFCell cell_4 = tRow.createCell((short) 4);
				HSSFCell cell_5 = tRow.createCell((short) 5);
				HSSFCell cell_6 = tRow.createCell((short) 6);
				HSSFCell cell_7 = tRow.createCell((short) 7);
				HSSFCell cell_8 = tRow.createCell((short) 8);

				zongjiCell.setCellStyle(cStyleM_R);
				cell_1.setCellStyle(cStyleM_R);
				cell_2.setCellStyle(cStyleM_R);
				cell_3.setCellStyle(cStyleM_R);
				cell_4.setCellStyle(cStyleM_R);
				cell_5.setCellStyle(cStyleM_R);
				cell_6.setCellStyle(cStyleM_R);
				cell_7.setCellStyle(cStyleM_R);
				cell_8.setCellStyle(cStyleM_R);

				zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);

				zongjiCell.setCellValue("合计：");
				cell_1.setCellValue(StringUtil.showPrice(String.valueOf(totalMonthMoney)));
				cell_2.setCellValue(StringUtil.showPrice(String.valueOf(totalInMoney1)));
				cell_3.setCellValue(StringUtil.showPrice(String.valueOf(totalInMoney2)));
				cell_4.setCellValue(StringUtil.showPrice(String.valueOf(totalAllInMoney)));
				cell_5.setCellValue(StringUtil.showPrice(String.valueOf(totalOutMoney1)));
				cell_6.setCellValue(StringUtil.showPrice(String.valueOf(totalOutMoney2)));
				cell_7.setCellValue(StringUtil.showPrice(String.valueOf(totalAllOutMoney)));
				cell_8.setCellValue(StringUtil.showPrice(String.valueOf(totalMoney)));

			}

			fileName = fileName + ".xls";
			response.setHeader("Cache-Control", "No-cache");
			response.setHeader("Pragma", "No-cache");
			response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
			response.setDateHeader("Expires", 0);
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();

			tWb.write(out);

			out.flush();
			out.close();

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {
				if (con != null) {
					con.close();
				}
				if (out != null) {
					out.close();
				}
			} catch (Exception ex1) {

			}
		}
	}

	/**
	 * 报表6 合并库收料清单（修理公司）
	 * 
	 * @param aList
	 * @param title
	 * @param start
	 * @param end
	 */
	private void writeExcel_ReportCustomerInList(String warehouseCode, String inCustomerName, String getCustomers, String title, String fileName,
			ObjectList aList, ObjectList aListAll, String title1, String start, String end, HttpServletRequest request, HttpServletResponse response) {
		DBConnection con = null;
		ServletOutputStream out = null;
		try {
			HSSFWorkbook tWb = new HSSFWorkbook();
			HSSFSheet tSheet = tWb.createSheet();
			HSSFRow tRow = null;
			Region region = null;
			tSheet.setColumnWidth((short) 0, (short) (16 * 256));
			tSheet.setColumnWidth((short) 1, (short) (12 * 256));
			tSheet.setColumnWidth((short) 2, (short) (12 * 256));
			tSheet.setColumnWidth((short) 3, (short) (18 * 256));

			tWb.setSheetName(0, title1, HSSFCell.ENCODING_UTF_16);

			HSSFFont font = tWb.createFont();
			font.setFontHeightInPoints((short) 9);
			font.setFontName("宋体");
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

			HSSFCellStyle cStyle = tWb.createCellStyle();
			cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			HSSFCellStyle cStyleM = tWb.createCellStyle();
			cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM.setFont(font);

			HSSFCellStyle cStyleM_R = tWb.createCellStyle();
			cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			cStyleM_R.setFont(font);

			// 标题行
			tRow = tSheet.createRow((short) 0);
			HSSFCell c0 = createCell(tWb, tRow, (short) 3, title1);
			c0.setCellStyle(cStyleM);
			// 日期行
			tRow = tSheet.createRow((short) 1);
			region = new Region(1, (short) 2, 1, (short) 7);
			tSheet.addMergedRegion(region);
			createCell(tWb, tRow, (short) 2, "供货单位:" + inCustomerName + "     " + start + " 至 " + end, HSSFCellStyle.ALIGN_LEFT, false);

			// 表头行
			tRow = tSheet.createRow((short) 2);

			HSSFCell c1 = createCell(tWb, tRow, (short) 0, "网上编码");
			HSSFCell c2 = createCell(tWb, tRow, (short) 1, "材料自编号");
			HSSFCell c3 = createCell(tWb, tRow, (short) 2, "材料名称");
			HSSFCell c4 = createCell(tWb, tRow, (short) 3, "规格");
			HSSFCell c5 = createCell(tWb, tRow, (short) 4, "帐本号");
			HSSFCell c6 = createCell(tWb, tRow, (short) 5, "单价");
			HSSFCell c7 = createCell(tWb, tRow, (short) 6, "入库数量");
			HSSFCell c8 = createCell(tWb, tRow, (short) 7, "入库金额");
			c1.setCellStyle(cStyleM_R);
			c2.setCellStyle(cStyleM_R);
			c3.setCellStyle(cStyleM_R);
			c4.setCellStyle(cStyleM_R);
			c5.setCellStyle(cStyleM_R);
			c6.setCellStyle(cStyleM_R);
			c7.setCellStyle(cStyleM_R);
			c8.setCellStyle(cStyleM_R);

			// String[] tTemp;
			double totalMoney = 0;
			double totalPrice = 0;
			double totalCount = 0;

			int regionBegin = 0;
			int regionEnd = 0;
			// String currentDept = "";
			short index = 2; // 当前所在行号
			BigDecimal zongji = new BigDecimal("0");
			double money = 0;
			double price = 0;
			double count = 0;

			String concentricityCode = "";
			String apepCode = "";
			String name = "";
			String spec = "";
			String warehouseCategory = "";

			con = DBConnection.open(false);

			for (int i = 0; i < aList.size(); i++) {
				UniversalRow row = (UniversalRow) aList.get(i);
				// -----------------------
				// 统计领料单位出库总金额
				for (int j = 0; j < aListAll.size(); j++) {
					UniversalRow rowAll = (UniversalRow) aListAll.get(j);
					if (rowAll.getString("CONCENTRICITY_CODE").equals(row.getString("CODE"))) {
						money += Double.parseDouble(rowAll.getString("MONEY"));
						price += Double.parseDouble(rowAll.getString("PRICE"));
						count += Double.parseDouble(rowAll.getString("COUNT"));

						concentricityCode = rowAll.getString("CONCENTRICITY_CODE");
						apepCode = rowAll.getString("APEP_CODE");
						name = rowAll.getString("NAME");
						spec = rowAll.getString("SPEC");
					}

				}

				totalMoney += money;
				totalPrice += price;
				totalCount += count;

				// -----------------------
				WarehouseCategoryRelation wcr = WarehouseCategoryRelation.fetchbyProductWarehouseCode(con, concentricityCode, warehouseCode);
				if (wcr == null) {
					warehouseCategory = "";
				} else {
					warehouseCategory = wcr.getCategoryCode();
				}

				tRow = tSheet.createRow((short) (index + 1));

				createCell(tWb, tRow, (short) 0, concentricityCode);
				createCell(tWb, tRow, (short) 1, apepCode);
				createCell(tWb, tRow, (short) 2, name);
				createCell(tWb, tRow, (short) 3, spec);
				createCell(tWb, tRow, (short) 4, warehouseCategory);
				createCell(tWb, tRow, (short) 5, StringUtil.showPrice(price, 4));
				createCell(tWb, tRow, (short) 6, StringUtil.showCount(String.valueOf(count)));
				createCell(tWb, tRow, (short) 7, StringUtil.showPrice(String.valueOf(money)));

				index++;

				money = 0;
				price = 0;
				count = 0;
				concentricityCode = "";
				apepCode = "";
				name = "";
				spec = "";

				row = null;
			}
			if (index > 2) {
				// 創建最後一個統計行
				tRow = tSheet.createRow((short) (index + 1));
				HSSFCell tongjiCell = tRow.createCell((short) 1);
				HSSFCell cell_1 = tRow.createCell((short) 5);
				HSSFCell cell_2 = tRow.createCell((short) 6);
				HSSFCell cell_3 = tRow.createCell((short) 7);

				tongjiCell.setCellStyle(cStyleM_R);
				cell_1.setCellStyle(cStyleM_R);
				cell_2.setCellStyle(cStyleM_R);
				cell_3.setCellStyle(cStyleM_R);

				// HSSFCell tongjiCell = tRow.createCell((short)1);
				tongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);

				tongjiCell.setCellValue("合计:");
				cell_1.setCellValue(StringUtil.showPrice(totalPrice, 4));
				cell_2.setCellValue(StringUtil.showCount(String.valueOf(totalCount)));
				cell_3.setCellValue(StringUtil.showPrice(String.valueOf(totalMoney)));
			}

			fileName = fileName + ".xls";
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();
			tWb.write(out);

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {
				if (con != null) {
					con.close();
				}
				if (out != null) {
					out.close();
				}
			} catch (Exception ex1) {

			}
		}
	}

	private HSSFCell createCell(HSSFWorkbook aWb, HSSFRow aRow, short column, String alaValueue) {
		HSSFCell tCell = aRow.createCell(column);
		tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
		tCell.setCellValue(alaValueue);
		return tCell;
	}

	private HSSFCell createCell(HSSFWorkbook aWb, HSSFRow aRow, short column, String aValue, short aAlign, boolean border) {
		HSSFCell tCell = aRow.createCell(column);
		tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
		tCell.setCellValue(aValue);
		HSSFCellStyle tCellStyle = aWb.createCellStyle();
		tCellStyle.setAlignment(aAlign);
		tCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
		if (border) {
			tCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
			tCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
			tCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
			tCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
			tCellStyle.setBottomBorderColor(HSSFColor.BLACK.index);
			tCellStyle.setTopBorderColor(HSSFColor.BLACK.index);
			tCellStyle.setRightBorderColor(HSSFColor.BLACK.index);
			tCellStyle.setLeftBorderColor(HSSFColor.BLACK.index);
		}
		tCell.setCellStyle(tCellStyle);
		return tCell;
	}

	private HSSFCell createCell(HSSFWorkbook aWb, HSSFRow aRow, short column, String aValue, short aAlign, short bAlign) {
		HSSFCell tCell = aRow.createCell(column);
		tCell.setEncoding(HSSFCell.ENCODING_UTF_16);
		tCell.setCellValue(aValue);
		HSSFCellStyle tCellStyle = aWb.createCellStyle();
		tCellStyle.setAlignment(aAlign);
		tCellStyle.setVerticalAlignment(bAlign);

		tCell.setCellStyle(tCellStyle);
		return tCell;
	}

	/** EXCEL 处理 报表① */
	private void writeExcel_ReportYKProduct(String month, String title, String fileName, Vector vec, String title1, String start, String end,
			String warehouseCode, HttpServletRequest request, HttpServletResponse response) {
		ServletOutputStream out = null;
		try {
			/** 创建通用EXCEL 开始 */
			HSSFWorkbook tWb = new HSSFWorkbook();
			HSSFSheet tSheet = null;
			HSSFRow tRow = null;
			Region region = null;
			HSSFCell c0 = null;
			HSSFCell c1 = null;
			HSSFCell c2 = null;
			HSSFCell c3 = null;
			HSSFCell c4 = null;
			HSSFCell c5 = null;
			HSSFCell c6 = null;
			HSSFCell c7 = null;
			HSSFCell c8 = null;
			HSSFCell c9 = null;
			HSSFCell c10 = null;
			HSSFCell c11 = null;
			HSSFCell c12 = null;
			HSSFCell c13 = null;
			HSSFCell c14 = null;
			HSSFCell c15 = null;
			HSSFFont font = tWb.createFont();
			font.setFontHeightInPoints((short) 9);
			font.setFontName("宋体");
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
			HSSFCellStyle cStyle = tWb.createCellStyle();
			cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			HSSFCellStyle cStyleM = tWb.createCellStyle();
			cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM.setFont(font);
			HSSFCellStyle cStyleM_R = tWb.createCellStyle();
			cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			cStyleM_R.setFont(font);
			/** 创建通用EXCEL 结束 */

			/** 创建Sheet 开始 */
			for (int k = 0; k < vec.size(); k++) {
				Vector vec1 = (Vector) vec.get(k);
				short index = 2; // 当前所在行号
				double totalMonthStorageMoney = 0;
				double totalMonthStorageCount = 0;
				double totalInCount = 0;
				double totalInMoney = 0;
				double totalOutCount = 0;
				double totalOutMoney = 0;
				double totalMonthEndCount = 0;
				double totalMonthEndMoney = 0;
				String productCode = "";
				String productName = "";
				String spec = "";
				String model = "";
				String brand = "";
				String unit = "";
				String productApepCode = "";
				// 创建 sheet
				tSheet = tWb.createSheet();
				ProviderTemp pt = (ProviderTemp) vec1.get(0);
				tWb.setSheetName(k, pt.ProviderName + pt.providerCode, HSSFCell.ENCODING_UTF_16);
				tSheet.setColumnWidth((short) 0, (short) (16 * 256));
				tSheet.setColumnWidth((short) 1, (short) (12 * 256));
				tSheet.setColumnWidth((short) 2, (short) (12 * 256));
				tSheet.setColumnWidth((short) 3, (short) (18 * 256));
				tSheet.setColumnWidth((short) 4, (short) (10 * 256));
				tSheet.setColumnWidth((short) 5, (short) (10 * 256));
				tSheet.setColumnWidth((short) 6, (short) (10 * 256));
				tSheet.setColumnWidth((short) 7, (short) (10 * 256));
				tSheet.setColumnWidth((short) 8, (short) (10 * 256));
				tSheet.setColumnWidth((short) 9, (short) (12 * 256));
				tSheet.setColumnWidth((short) 10, (short) (14 * 256));
				tSheet.setColumnWidth((short) 11, (short) (14 * 256));
				tSheet.setColumnWidth((short) 12, (short) (14 * 256));
				tSheet.setColumnWidth((short) 13, (short) (14 * 256));
				tSheet.setColumnWidth((short) 14, (short) (14 * 256));
				tSheet.setColumnWidth((short) 15, (short) (14 * 256));
				// 标题行
				tRow = tSheet.createRow((short) 0);
				c0 = createCell(tWb, tRow, (short) 5, title1);
				c0.setCellStyle(cStyleM);
				// 日期行
				tRow = tSheet.createRow((short) 1);
				region = new Region(1, (short) 9, 1, (short) 13);
				tSheet.addMergedRegion(region);
				createCell(tWb, tRow, (short) 9, "供应商:" + pt.ProviderName + "     " + start + " 至 " + end, HSSFCellStyle.ALIGN_CENTER, false);
				// 表头行
				tRow = tSheet.createRow((short) 2);
				c1 = createCell(tWb, tRow, (short) 0, "产品编码");
				c2 = createCell(tWb, tRow, (short) 1, "自编码");
				c3 = createCell(tWb, tRow, (short) 2, "产品名称");
				c4 = createCell(tWb, tRow, (short) 3, "规格");
				c5 = createCell(tWb, tRow, (short) 4, "型号");
				c6 = createCell(tWb, tRow, (short) 5, "品牌");
				c7 = createCell(tWb, tRow, (short) 6, "单位");
				c8 = createCell(tWb, tRow, (short) 7, "单价");
				c9 = createCell(tWb, tRow, (short) 8, "期初数量");
				c10 = createCell(tWb, tRow, (short) 9, "期初金额");
				c11 = createCell(tWb, tRow, (short) 10, "入库数量");
				c12 = createCell(tWb, tRow, (short) 11, "入库金额");
				c13 = createCell(tWb, tRow, (short) 12, "领出数量");
				c14 = createCell(tWb, tRow, (short) 13, "领出金额");
				c15 = createCell(tWb, tRow, (short) 14, "期末数量");
				c0 = createCell(tWb, tRow, (short) 15, "期末金额");
				c1.setCellStyle(cStyleM_R);
				c2.setCellStyle(cStyleM_R);
				c3.setCellStyle(cStyleM_R);
				c4.setCellStyle(cStyleM_R);
				c5.setCellStyle(cStyleM_R);
				c6.setCellStyle(cStyleM_R);
				c7.setCellStyle(cStyleM_R);
				c8.setCellStyle(cStyleM_R);
				c9.setCellStyle(cStyleM_R);
				c10.setCellStyle(cStyleM_R);
				c11.setCellStyle(cStyleM_R);
				c12.setCellStyle(cStyleM_R);
				c13.setCellStyle(cStyleM_R);
				c14.setCellStyle(cStyleM_R);
				c15.setCellStyle(cStyleM_R);
				c0.setCellStyle(cStyleM_R);
				// 期初计算
				for (int i = 1; i < vec1.size(); i++) {
					String[] values = (String[]) vec1.get(i);
					double productMonthMoney = 0;
					double productMonthCount = 0;
					double productInCount = 0;
					double productInMoney = 0;
					double productOutCount = 0;
					double productOutMoney = 0;
					double monthEndCount = 0;
					double monthEndMoney = 0;
					productMonthCount = Double.parseDouble(values[1]);
					productMonthMoney = Double.parseDouble(values[2]);

					productInCount = Double.parseDouble(values[3]);
					productInMoney = Double.parseDouble(values[4]);

					productOutCount = Double.parseDouble(values[5]);
					productOutMoney = Double.parseDouble(values[6]);

					monthEndCount = Double.parseDouble(values[7]);
					monthEndMoney = Double.parseDouble(values[8]);
					// 創建一行
					tRow = tSheet.createRow((short) (index + 1));
					createCell(tWb, tRow, (short) 0, values[0]);
					createCell(tWb, tRow, (short) 1, values[9] == null ? "" : values[9]);
					createCell(tWb, tRow, (short) 2, values[10] == null ? "" : values[10]);
					createCell(tWb, tRow, (short) 3, values[11] == null ? "" : values[11]);
					createCell(tWb, tRow, (short) 4, values[12] == null ? "" : values[12]);
					createCell(tWb, tRow, (short) 5, values[13] == null ? "" : values[13]);
					createCell(tWb, tRow, (short) 6, values[14] == null ? "" : values[14]);
					createCell(tWb, tRow, (short) 7, StringUtil.showCount(values[15]));
					createCell(tWb, tRow, (short) 8, StringUtil.showCount(String.valueOf(productMonthCount)));
					createCell(tWb, tRow, (short) 9, StringUtil.showPrice(String.valueOf(productMonthMoney)));
					createCell(tWb, tRow, (short) 10, StringUtil.showCount(String.valueOf(productInCount)));
					createCell(tWb, tRow, (short) 11, StringUtil.showPrice(String.valueOf(productInMoney)));
					createCell(tWb, tRow, (short) 12, StringUtil.showCount(String.valueOf(productOutCount)));
					createCell(tWb, tRow, (short) 13, StringUtil.showPrice(String.valueOf(productOutMoney)));
					createCell(tWb, tRow, (short) 14, StringUtil.showCount(String.valueOf(monthEndCount)));
					createCell(tWb, tRow, (short) 15, StringUtil.showPrice(String.valueOf(monthEndMoney)));
					totalInCount += productInCount;
					totalInMoney += productInMoney;
					totalOutCount += productOutCount;
					totalOutMoney += productOutMoney;
					totalMonthStorageCount += productMonthCount;
					totalMonthStorageMoney += productMonthMoney;
					totalMonthEndCount += monthEndCount;
					totalMonthEndMoney += monthEndMoney;
					index++;
				}

				// 总计行
				if (index > 2) {
					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell zongjiCell = tRow.createCell((short) 5);
					HSSFCell cell_1 = tRow.createCell((short) 8);
					HSSFCell cell_2 = tRow.createCell((short) 9);
					HSSFCell cell_3 = tRow.createCell((short) 10);
					HSSFCell cell_4 = tRow.createCell((short) 11);
					HSSFCell cell_5 = tRow.createCell((short) 12);
					HSSFCell cell_6 = tRow.createCell((short) 13);
					HSSFCell cell_7 = tRow.createCell((short) 14);
					HSSFCell cell_8 = tRow.createCell((short) 15);
					zongjiCell.setCellStyle(cStyleM_R);
					cell_1.setCellStyle(cStyleM_R);
					cell_2.setCellStyle(cStyleM_R);
					cell_3.setCellStyle(cStyleM_R);
					cell_4.setCellStyle(cStyleM_R);
					cell_5.setCellStyle(cStyleM_R);
					cell_6.setCellStyle(cStyleM_R);
					cell_7.setCellStyle(cStyleM_R);
					cell_8.setCellStyle(cStyleM_R);
					zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);
					zongjiCell.setCellValue("合计:");
					cell_1.setCellValue(StringUtil.showCount(String.valueOf(totalMonthStorageCount)));
					cell_2.setCellValue(StringUtil.showPrice(String.valueOf(totalMonthStorageMoney)));
					cell_3.setCellValue(StringUtil.showCount(String.valueOf(totalInCount)));
					cell_4.setCellValue(StringUtil.showPrice(String.valueOf(totalInMoney)));
					cell_5.setCellValue(StringUtil.showCount(String.valueOf(totalOutCount)));
					cell_6.setCellValue(StringUtil.showPrice(String.valueOf(totalOutMoney)));
					cell_7.setCellValue(StringUtil.showCount(String.valueOf(totalMonthEndCount)));
					cell_8.setCellValue(StringUtil.showPrice(String.valueOf(totalMonthEndMoney)));
				}
			}

			/** 输出EXCEL文件 开始 */
			fileName = fileName + ".xls";
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();
			tWb.write(out);
			/** 输出EXCEL文件 结束 */
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}
		}
	}

	/** EXCEL 处理 报表18*/
	private void writeExcel_ReportYKProductAll(String month, String title, String fileName, Vector vec, String title1, String start, String end,
			String warehouseCode, HttpServletRequest request, HttpServletResponse response) {
		ServletOutputStream out = null;
		try {
			/** 创建通用EXCEL 开始 */
			HSSFWorkbook tWb = new HSSFWorkbook();
			Region region = null;
			HSSFSheet tSheet = null;
			HSSFRow tRow = null;
			HSSFCell c0 = null;
			HSSFCell c1 = null;
			HSSFCell c2 = null;
			HSSFCell c3 = null;
			HSSFCell c4 = null;
			HSSFCell c5 = null;
			HSSFCell c6 = null;
			HSSFCell c7 = null;
			HSSFCell c8 = null;
			HSSFCell c9 = null;
			HSSFCell c10 = null;
			HSSFCell c11 = null;
			HSSFCell c12 = null;
			HSSFCell c13 = null;
			HSSFCell c14 = null;
			HSSFCell c15 = null;
			HSSFCell c16 = null;
			HSSFFont font = tWb.createFont();
			font.setFontHeightInPoints((short) 9);
			font.setFontName("宋体");
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
			HSSFCellStyle cStyle = tWb.createCellStyle();
			cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			HSSFCellStyle cStyleM = tWb.createCellStyle();
			cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM.setFont(font);
			HSSFCellStyle cStyleM_R = tWb.createCellStyle();
			cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			cStyleM_R.setFont(font);
			/** 创建通用EXCEL 结束 */


			/** 创建Sheet 开始 */
			tSheet = tWb.createSheet();

			tWb.setSheetName(0, "仓库产品进、销、存供应商分类报表", HSSFCell.ENCODING_UTF_16);
			tSheet.setColumnWidth((short) 0, (short) (16 * 256));
			tSheet.setColumnWidth((short) 1, (short) (12 * 256));
			tSheet.setColumnWidth((short) 2, (short) (12 * 256));
			tSheet.setColumnWidth((short) 3, (short) (18 * 256));
			tSheet.setColumnWidth((short) 4, (short) (10 * 256));
			tSheet.setColumnWidth((short) 5, (short) (10 * 256));
			tSheet.setColumnWidth((short) 6, (short) (10 * 256));
			tSheet.setColumnWidth((short) 7, (short) (10 * 256));
			tSheet.setColumnWidth((short) 8, (short) (10 * 256));
			tSheet.setColumnWidth((short) 9, (short) (12 * 256));
			tSheet.setColumnWidth((short) 10, (short) (14 * 256));
			tSheet.setColumnWidth((short) 11, (short) (14 * 256));
			tSheet.setColumnWidth((short) 12, (short) (14 * 256));
			tSheet.setColumnWidth((short) 13, (short) (14 * 256));
			tSheet.setColumnWidth((short) 14, (short) (14 * 256));
			tSheet.setColumnWidth((short) 15, (short) (14 * 256));
			tSheet.setColumnWidth((short) 16, (short) (14 * 256));//供应商

			// 标题行
			tRow = tSheet.createRow((short) 0);
			c0 = createCell(tWb, tRow, (short) 5, title1);
			c0.setCellStyle(cStyleM);
			// 日期行
			tRow = tSheet.createRow((short) 1);
			region = new Region(1, (short) 9, 1, (short) 13);
			tSheet.addMergedRegion(region);
			createCell(tWb, tRow, (short) 9, "               " + start + " 至 " + end, HSSFCellStyle.ALIGN_CENTER, false);

			// 表头行
			tRow = tSheet.createRow((short) 2);
			c1 = createCell(tWb, tRow, (short) 0, "产品编码");
			c2 = createCell(tWb, tRow, (short) 1, "自编码");
			c3 = createCell(tWb, tRow, (short) 2, "产品名称");
			c4 = createCell(tWb, tRow, (short) 3, "规格");
			c5 = createCell(tWb, tRow, (short) 4, "型号");
			c6 = createCell(tWb, tRow, (short) 5, "品牌");
			c7 = createCell(tWb, tRow, (short) 6, "单位");
			c8 = createCell(tWb, tRow, (short) 7, "单价");
			c9 = createCell(tWb, tRow, (short) 8, "期初数量");
			c10 = createCell(tWb, tRow, (short) 9, "期初金额");
			c11 = createCell(tWb, tRow, (short) 10, "入库数量");
			c12 = createCell(tWb, tRow, (short) 11, "入库金额");
			c13 = createCell(tWb, tRow, (short) 12, "领出数量");
			c14 = createCell(tWb, tRow, (short) 13, "领出金额");
			c15 = createCell(tWb, tRow, (short) 14, "期末数量");
			c0 = createCell(tWb, tRow, (short) 15, "期末金额");
			c16 = createCell(tWb, tRow, (short) 16, "供应商");
			c1.setCellStyle(cStyleM_R);
			c2.setCellStyle(cStyleM_R);
			c3.setCellStyle(cStyleM_R);
			c4.setCellStyle(cStyleM_R);
			c5.setCellStyle(cStyleM_R);
			c6.setCellStyle(cStyleM_R);
			c7.setCellStyle(cStyleM_R);
			c8.setCellStyle(cStyleM_R);
			c9.setCellStyle(cStyleM_R);
			c10.setCellStyle(cStyleM_R);
			c11.setCellStyle(cStyleM_R);
			c12.setCellStyle(cStyleM_R);
			c13.setCellStyle(cStyleM_R);
			c14.setCellStyle(cStyleM_R);
			c15.setCellStyle(cStyleM_R);
			c0.setCellStyle(cStyleM_R);
			c16.setCellStyle(cStyleM_R);
			short index = 2;
			double totalMonthStorageMoney = 0;
			double totalMonthStorageCount = 0;
			double totalInCount = 0;
			double totalInMoney = 0;
			double totalOutCount = 0;
			double totalOutMoney = 0;
			double totalMonthEndCount = 0;
			double totalMonthEndMoney = 0;
			for (int k = 0; k < vec.size(); k++) {
				Vector vec1 = (Vector) vec.get(k);
				String productCode = "";
				String productName = "";
				String spec = "";
				String model = "";
				String brand = "";
				String unit = "";
				String productApepCode = "";
				ProviderTemp pt = (ProviderTemp) vec1.get(0);

				// 期初计算
				for (int i = 1; i < vec1.size(); i++) {
					String[] values = (String[]) vec1.get(i);
					double productMonthMoney = 0;
					double productMonthCount = 0;
					double productInCount = 0;
					double productInMoney = 0;
					double productOutCount = 0;
					double productOutMoney = 0;
					double monthEndCount = 0;
					double monthEndMoney = 0;
					productMonthCount = Double.parseDouble(values[1]);
					productMonthMoney = Double.parseDouble(values[2]);

					productInCount = Double.parseDouble(values[3]);
					productInMoney = Double.parseDouble(values[4]);

					productOutCount = Double.parseDouble(values[5]);
					productOutMoney = Double.parseDouble(values[6]);

					monthEndCount = Double.parseDouble(values[7]);
					monthEndMoney = Double.parseDouble(values[8]);
					// 創建一行
					tRow = tSheet.createRow((short) (index + 1));
					createCell(tWb, tRow, (short) 0, values[0]);
					createCell(tWb, tRow, (short) 1, values[9] == null ? "" : values[9]);
					createCell(tWb, tRow, (short) 2, values[10] == null ? "" : values[10]);
					createCell(tWb, tRow, (short) 3, values[11] == null ? "" : values[11]);
					createCell(tWb, tRow, (short) 4, values[12] == null ? "" : values[12]);
					createCell(tWb, tRow, (short) 5, values[13] == null ? "" : values[13]);
					createCell(tWb, tRow, (short) 6, values[14] == null ? "" : values[14]);
					createCell(tWb, tRow, (short) 7, StringUtil.showCount(values[15]));
					createCell(tWb, tRow, (short) 8, StringUtil.showCount(String.valueOf(productMonthCount)));
					createCell(tWb, tRow, (short) 9, StringUtil.showPrice(String.valueOf(productMonthMoney)));
					createCell(tWb, tRow, (short) 10, StringUtil.showCount(String.valueOf(productInCount)));
					createCell(tWb, tRow, (short) 11, StringUtil.showPrice(String.valueOf(productInMoney)));
					createCell(tWb, tRow, (short) 12, StringUtil.showCount(String.valueOf(productOutCount)));
					createCell(tWb, tRow, (short) 13, StringUtil.showPrice(String.valueOf(productOutMoney)));
					createCell(tWb, tRow, (short) 14, StringUtil.showCount(String.valueOf(monthEndCount)));
					createCell(tWb, tRow, (short) 15, StringUtil.showPrice(String.valueOf(monthEndMoney)));
					createCell(tWb, tRow, (short) 16, pt.ProviderName==null?"":pt.ProviderName);
					totalInCount += productInCount;
					totalInMoney += productInMoney;
					totalOutCount += productOutCount;
					totalOutMoney += productOutMoney;
					totalMonthStorageCount += productMonthCount;
					totalMonthStorageMoney += productMonthMoney;
					totalMonthEndCount += monthEndCount;
					totalMonthEndMoney += monthEndMoney;
					index++;
				}

			}
			// 总计行
			if (index > 2) {
				tRow = tSheet.createRow((short) (index + 2));
				HSSFCell zongjiCell = tRow.createCell((short) 5);
				HSSFCell cell_1 = tRow.createCell((short) 8);
				HSSFCell cell_2 = tRow.createCell((short) 9);
				HSSFCell cell_3 = tRow.createCell((short) 10);
				HSSFCell cell_4 = tRow.createCell((short) 11);
				HSSFCell cell_5 = tRow.createCell((short) 12);
				HSSFCell cell_6 = tRow.createCell((short) 13);
				HSSFCell cell_7 = tRow.createCell((short) 14);
				HSSFCell cell_8 = tRow.createCell((short) 15);
				zongjiCell.setCellStyle(cStyleM_R);
				cell_1.setCellStyle(cStyleM_R);
				cell_2.setCellStyle(cStyleM_R);
				cell_3.setCellStyle(cStyleM_R);
				cell_4.setCellStyle(cStyleM_R);
				cell_5.setCellStyle(cStyleM_R);
				cell_6.setCellStyle(cStyleM_R);
				cell_7.setCellStyle(cStyleM_R);
				cell_8.setCellStyle(cStyleM_R);
				zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);
				zongjiCell.setCellValue("合计:");
				cell_1.setCellValue(StringUtil.showCount(String.valueOf(totalMonthStorageCount)));
				cell_2.setCellValue(StringUtil.showPrice(String.valueOf(totalMonthStorageMoney)));
				cell_3.setCellValue(StringUtil.showCount(String.valueOf(totalInCount)));
				cell_4.setCellValue(StringUtil.showPrice(String.valueOf(totalInMoney)));
				cell_5.setCellValue(StringUtil.showCount(String.valueOf(totalOutCount)));
				cell_6.setCellValue(StringUtil.showPrice(String.valueOf(totalOutMoney)));
				cell_7.setCellValue(StringUtil.showCount(String.valueOf(totalMonthEndCount)));
				cell_8.setCellValue(StringUtil.showPrice(String.valueOf(totalMonthEndMoney)));
			}

			/** 输出EXCEL文件 开始 */
			fileName = fileName + ".xls";
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();
			tWb.write(out);
			/** 输出EXCEL文件 结束 */
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}
		}
	}

	/** 供应商内部类 */
	class ProviderTemp {
		// 供应商编码
		public String providerCode = "";
		// 供应商名称
		public String ProviderName = "";
		public ObjectList listOut = null;
		public ObjectList listIn = null;
		public ObjectList list = null;
	}

	/** 在一个月中 已给出时间 最早start,最终得到 本月的第一天和早于start的最晚时间 */
	private String[] getBeforetime(String start) {
		String[] strs = new String[] { "9999-99-99 99:99:99", "0000-00-00 00:00:00" };
		StringBuffer beforeStart = new StringBuffer(start);
		StringBuffer beforeEnd = new StringBuffer(start);
		beforeStart = beforeStart.replace(8, 10, "01");
		int day = Integer.parseInt(String.valueOf(start.subSequence(8, 10)));
		if (day > 1) {
			day--;
		} else {
			return strs;
		}
		String strDay = null;
		if (day < 10) {
			strDay = "0" + day;
		} else {
			strDay = String.valueOf(day);
		}
		beforeEnd = beforeEnd.replace(8, 10, strDay);
		String str1 = String.valueOf(beforeStart);
		String str2 = String.valueOf(beforeEnd);
		strs[0] = str1 + " 00:00:00";
		strs[1] = str2 + " 23:59:59";
		return strs;
	}

	private void writeExcel_ReportSeventh(Vector vec, String warehouseCode, String month, String title, String fileName, String title1,
			HttpServletRequest request, HttpServletResponse response, String start, String end, DBConnection con) {
		ServletOutputStream out = null;
		try {
			/** 创建通用EXCEL 开始 */
			HSSFWorkbook tWb = new HSSFWorkbook();
			HSSFSheet tSheet = null;
			HSSFRow tRow = null;
			Region region = null;
			HSSFCell c0 = null;
			HSSFCell c1 = null;
			HSSFCell c2 = null;
			HSSFCell c3 = null;
			HSSFCell c4 = null;
			HSSFCell c5 = null;
			HSSFCell c6 = null;
			HSSFCell c7 = null;
			HSSFCell c8 = null;
			HSSFCell c9 = null;
			HSSFCell c10 = null;
			HSSFCell c11 = null;
			HSSFCell c12 = null;
			HSSFCell c13 = null;
			HSSFCell c14 = null;
			HSSFCell c15 = null;
			HSSFFont font = tWb.createFont();
			font.setFontHeightInPoints((short) 9);
			font.setFontName("宋体");
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
			HSSFCellStyle cStyle = tWb.createCellStyle();
			cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			HSSFCellStyle cStyleM = tWb.createCellStyle();
			cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM.setFont(font);
			HSSFCellStyle cStyleM_R = tWb.createCellStyle();
			cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			cStyleM_R.setFont(font);
			/** 创建通用EXCEL 结束 */

			/** 创建Sheet 开始 */
			int size = vec.size();// 获得结果集大小
			boolean needNew = true;// 标示变量 当需要创建一个新的sheet页的时候 值为true
			String category_code1 = null;// 存储索引i的类别编号
			String category_code2 = null;// 存储索引i+1的类别编号
			String category_name = null;// 当前的类别名称
			short index = 2; // 当前所在行号
			double totalMonthStorageMoney = 0;// 一个sheet中用来统计合计
			double totalMonthStorageCount = 0;// 一个sheet中用来统计合计
			double totalInCount = 0;// 一个sheet中用来统计合计
			double totalInMoney = 0;// 一个sheet中用来统计合计
			double totalOutCount = 0;// 一个sheet中用来统计合计
			double totalOutMoney = 0;// 一个sheet中用来统计合计
			double totalMonthEndCount = 0;// 一个sheet中用来统计合计
			double totalMonthEndMoney = 0;// 一个sheet中用来统计合计
			int sheetIndex = 0;// sheet创建所需要的索引
			for (int k = 0; k < size; k++) {
				System.out.println(k);
				Map map1 = (Map) vec.get(k);
				Map map2 = null;
				category_name = map1.get("CATE_NAME") == null ? "" : (String) map1.get("CATE_NAME");// 获取当前索引的类型名称
				if (size > 1 && k != size - 1) {
					map2 = (Map) vec.get(k + 1);// 如果集合大于2并且当前不是最后一位索引
				}
				// 获取下一位索引的对象
				if (map2 != null) {
					category_code1 = (String) map1.get("CATEGORY_CODE");
					category_code2 = (String) map2.get("CATEGORY_CODE");
				}
				// 创建 sheet 当条件满足时
				if (needNew) {
					tSheet = tWb.createSheet();
					tWb.setSheetName(sheetIndex, category_name, HSSFCell.ENCODING_UTF_16);
					tSheet.setColumnWidth((short) 0, (short) (16 * 256));
					tSheet.setColumnWidth((short) 1, (short) (12 * 256));
					tSheet.setColumnWidth((short) 2, (short) (12 * 256));
					tSheet.setColumnWidth((short) 3, (short) (18 * 256));
					tSheet.setColumnWidth((short) 4, (short) (10 * 256));
					tSheet.setColumnWidth((short) 5, (short) (10 * 256));
					tSheet.setColumnWidth((short) 6, (short) (10 * 256));
					tSheet.setColumnWidth((short) 7, (short) (10 * 256));
					tSheet.setColumnWidth((short) 8, (short) (10 * 256));
					tSheet.setColumnWidth((short) 9, (short) (12 * 256));
					tSheet.setColumnWidth((short) 10, (short) (14 * 256));
					tSheet.setColumnWidth((short) 11, (short) (14 * 256));
					tSheet.setColumnWidth((short) 12, (short) (14 * 256));
					tSheet.setColumnWidth((short) 13, (short) (14 * 256));
					tSheet.setColumnWidth((short) 14, (short) (14 * 256));
					tSheet.setColumnWidth((short) 15, (short) (14 * 256));
					// 标题行
					tRow = tSheet.createRow((short) 0);
					c0 = createCell(tWb, tRow, (short) 5, title1);
					c0.setCellStyle(cStyleM);
					// 日期行
					tRow = tSheet.createRow((short) 1);
					region = new Region(1, (short) 9, 1, (short) 13);
					tSheet.addMergedRegion(region);
					createCell(tWb, tRow, (short) 9, "产品分类:" + category_name + "     " + start + " 至 " + end, HSSFCellStyle.ALIGN_CENTER, false);
					// 表头行
					tRow = tSheet.createRow((short) 2);
					c1 = createCell(tWb, tRow, (short) 0, "产品编码");
					c2 = createCell(tWb, tRow, (short) 1, "自编码");
					c3 = createCell(tWb, tRow, (short) 2, "产品名称");
					c4 = createCell(tWb, tRow, (short) 3, "规格");
					c5 = createCell(tWb, tRow, (short) 4, "型号");
					c6 = createCell(tWb, tRow, (short) 5, "品牌");
					c7 = createCell(tWb, tRow, (short) 6, "单位");
					c8 = createCell(tWb, tRow, (short) 7, "单价");
					c9 = createCell(tWb, tRow, (short) 8, "期初数量");
					c10 = createCell(tWb, tRow, (short) 9, "期初金额");
					c11 = createCell(tWb, tRow, (short) 10, "入库数量");
					c12 = createCell(tWb, tRow, (short) 11, "入库金额");
					c13 = createCell(tWb, tRow, (short) 12, "领出数量");
					c14 = createCell(tWb, tRow, (short) 13, "领出金额");
					c15 = createCell(tWb, tRow, (short) 14, "期末数量");
					c0 = createCell(tWb, tRow, (short) 15, "期末金额");
					c1.setCellStyle(cStyleM_R);
					c2.setCellStyle(cStyleM_R);
					c3.setCellStyle(cStyleM_R);
					c4.setCellStyle(cStyleM_R);
					c5.setCellStyle(cStyleM_R);
					c6.setCellStyle(cStyleM_R);
					c7.setCellStyle(cStyleM_R);
					c8.setCellStyle(cStyleM_R);
					c9.setCellStyle(cStyleM_R);
					c10.setCellStyle(cStyleM_R);
					c11.setCellStyle(cStyleM_R);
					c12.setCellStyle(cStyleM_R);
					c13.setCellStyle(cStyleM_R);
					c14.setCellStyle(cStyleM_R);
					c15.setCellStyle(cStyleM_R);
					c0.setCellStyle(cStyleM_R);
					sheetIndex++;
					needNew = false;
				}
				double productMonthMoney = 0;// 用来统计单行数据的
				double productMonthCount = 0;// 用来统计单行数据的
				double productInCount = 0;// 用来统计单行数据的
				double productInMoney = 0;// 用来统计单行数据的
				double productOutCount = 0;// 用来统计单行数据的
				double productOutMoney = 0;// 用来统计单行数据的
				double monthEndCount = 0;// 用来统计单行数据的
				double monthEndMoney = 0;// 用来统计单行数据的

				/** 获取本行中的数字数据 */
				productMonthCount = Double.parseDouble((String) map1.get("INIT_COUNT"));
				productMonthMoney = Double.parseDouble((String) map1.get("INIT_MONEY"));
				productInCount = Double.parseDouble((String) map1.get("IN_COUNT"));
				productInMoney = Double.parseDouble((String) map1.get("IN_MONEY"));
				productOutCount = Double.parseDouble((String) map1.get("OUT_COUNT"));
				productOutMoney = Double.parseDouble((String) map1.get("OUT_MONEY"));
				monthEndCount = Double.parseDouble((String) map1.get("FINAL_COUNT"));
				monthEndMoney = Double.parseDouble((String) map1.get("FINAL_MONEY"));
				/** 获取本行中的数字数据 */

				/** 为单元格填充相应数据 */
				tRow = tSheet.createRow((short) (index + 1));
				createCell(tWb, tRow, (short) 0, map1.get("CONCENTRICITY_CODE") == null ? "" : (String) map1.get("CONCENTRICITY_CODE"));
				createCell(tWb, tRow, (short) 1, map1.get("APEP_CODE") == null ? "" : (String) map1.get("APEP_CODE"));
				createCell(tWb, tRow, (short) 2, map1.get("NAME") == null ? "" : (String) map1.get("NAME"));
				createCell(tWb, tRow, (short) 3, map1.get("SPEC") == null ? "" : (String) map1.get("SPEC"));
				createCell(tWb, tRow, (short) 4, map1.get("MODEL") == null ? "" : (String) map1.get("MODEL"));
				createCell(tWb, tRow, (short) 5, map1.get("PRODUCT_BRAND") == null ? "" : (String) map1.get("PRODUCT_BRAND"));
				createCell(tWb, tRow, (short) 6, map1.get("PRODUCT_UNIT") == null ? "" : (String) map1.get("PRODUCT_UNIT"));
				createCell(tWb, tRow, (short) 7, StringUtil.showCount(String.valueOf(Double.parseDouble((String) map1.get("PRODUCT_PRICE")))));
				createCell(tWb, tRow, (short) 8, StringUtil.showCount(String.valueOf(productMonthCount)));
				createCell(tWb, tRow, (short) 9, StringUtil.showPrice(String.valueOf(productMonthMoney)));
				createCell(tWb, tRow, (short) 10, StringUtil.showCount(String.valueOf(productInCount)));
				createCell(tWb, tRow, (short) 11, StringUtil.showPrice(String.valueOf(productInMoney)));
				createCell(tWb, tRow, (short) 12, StringUtil.showCount(String.valueOf(productOutCount)));
				createCell(tWb, tRow, (short) 13, StringUtil.showPrice(String.valueOf(productOutMoney)));
				createCell(tWb, tRow, (short) 14, StringUtil.showCount(String.valueOf(monthEndCount)));
				createCell(tWb, tRow, (short) 15, StringUtil.showPrice(String.valueOf(monthEndMoney)));
				/** 为单元格填充相应数据 */

				/** 累加本行数据 */
				totalInCount += productInCount;
				totalInMoney += productInMoney;
				totalOutCount += productOutCount;
				totalOutMoney += productOutMoney;
				totalMonthStorageCount += productMonthCount;
				totalMonthStorageMoney += productMonthMoney;
				totalMonthEndCount += monthEndCount;
				totalMonthEndMoney += monthEndMoney;
				index++;
				/** 累加本行数据 */

				// 当发现 索引i与索引i+1的类别不同时
				if (!category_code1.equals(category_code2)) {
					needNew = true;
				}
				// 当发现本索引是集合最后一位时
				if (k == size - 1) {
					needNew = true;
				}
				// 如果本页行数大于2 并且 下一个索引的类别和本索引类别不同 结束本页 并填充本页合计
				if (index > 2 && needNew) {
					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell zongjiCell = tRow.createCell((short) 5);
					HSSFCell cell_1 = tRow.createCell((short) 8);
					HSSFCell cell_2 = tRow.createCell((short) 9);
					HSSFCell cell_3 = tRow.createCell((short) 10);
					HSSFCell cell_4 = tRow.createCell((short) 11);
					HSSFCell cell_5 = tRow.createCell((short) 12);
					HSSFCell cell_6 = tRow.createCell((short) 13);
					HSSFCell cell_7 = tRow.createCell((short) 14);
					HSSFCell cell_8 = tRow.createCell((short) 15);
					zongjiCell.setCellStyle(cStyleM_R);
					cell_1.setCellStyle(cStyleM_R);
					cell_2.setCellStyle(cStyleM_R);
					cell_3.setCellStyle(cStyleM_R);
					cell_4.setCellStyle(cStyleM_R);
					cell_5.setCellStyle(cStyleM_R);
					cell_6.setCellStyle(cStyleM_R);
					cell_7.setCellStyle(cStyleM_R);
					cell_8.setCellStyle(cStyleM_R);
					zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);
					zongjiCell.setCellValue("合计:");
					cell_1.setCellValue(StringUtil.showCount(String.valueOf(totalMonthStorageCount)));
					cell_2.setCellValue(StringUtil.showPrice(String.valueOf(totalMonthStorageMoney)));
					cell_3.setCellValue(StringUtil.showCount(String.valueOf(totalInCount)));
					cell_4.setCellValue(StringUtil.showPrice(String.valueOf(totalInMoney)));
					cell_5.setCellValue(StringUtil.showCount(String.valueOf(totalOutCount)));
					cell_6.setCellValue(StringUtil.showPrice(String.valueOf(totalOutMoney)));
					cell_7.setCellValue(StringUtil.showCount(String.valueOf(totalMonthEndCount)));
					cell_8.setCellValue(StringUtil.showPrice(String.valueOf(totalMonthEndMoney)));

					/** sheet统计数据回零 */
					index = 2; // 当前所在行号
					totalMonthStorageMoney = 0;
					totalMonthStorageCount = 0;
					totalInCount = 0;
					totalInMoney = 0;
					totalOutCount = 0;
					totalOutMoney = 0;
					totalMonthEndCount = 0;
					totalMonthEndMoney = 0;
					/** sheet统计数据回零 */
				}
			}

			/** 输出EXCEL文件 开始 */
			fileName = fileName + ".xls";
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();
			tWb.write(out);
			/** 输出EXCEL文件 结束 */
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}
		}
	}

	/**
	 * 报表14 仓储系统入.出.存资金汇总月报
	 * 
	 */
	private void writeExcel(List list, String fileName, HttpServletResponse response, int year, int month) throws Exception {
		HSSFWorkbook book = new HSSFWorkbook();// 创建主文件
		HSSFSheet sheet = book.createSheet();// 创建sheet
		HSSFRow customRow = null;// 创建行

		String title = year + "年" + month + "月仓储系统入.出.存资金汇总月报";
		book.setSheetName(0, title, HSSFCell.ENCODING_UTF_16);// 设置sheet名称

		HSSFFont font = book.createFont();// 设置字体
		font.setFontHeightInPoints((short) 9);// 设置字体
		font.setFontName("宋体");// 设置字体
		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 设置字体

		HSSFCellStyle cStyle = book.createCellStyle();// 设置单元格样式
		cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);// 右对齐

		HSSFCellStyle cStyleM = book.createCellStyle();// 设置单元格样式
		cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 居中
		cStyleM.setFont(font);// 设置单元格字体

		HSSFCellStyle cStyleM_R = book.createCellStyle();// 设置单元格样式
		cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);// 右对齐
		cStyleM_R.setFont(font);// 设置单元格字体

		customRow = sheet.createRow((short) 0);// 标题行
		Region region = new Region(0, (short) 0, 0, (short) 9);// 合并0行0列到0行9列
		sheet.addMergedRegion(region);
		HSSFCell cTitle = createCell(book, customRow, (short) 0, title);// 设置标题行名称
		cTitle.setCellStyle(cStyleM);// 设置对其样式

		customRow = sheet.createRow((short) 1);// 创建列标头行
		HSSFCell c0 = createCell(book, customRow, (short) 0, "单位");
		HSSFCell c1 = createCell(book, customRow, (short) 1, "结算模式");
		HSSFCell c2 = createCell(book, customRow, (short) 2, "期初金额");
		HSSFCell c3 = createCell(book, customRow, (short) 3, "入库金额");
		HSSFCell c4 = createCell(book, customRow, (short) 4, "出库金额");
		HSSFCell c5 = createCell(book, customRow, (short) 5, "入出库金额合计");
		HSSFCell c6 = createCell(book, customRow, (short) 6, "期未金额");
		HSSFCell c7 = createCell(book, customRow, (short) 7, "入库单据(张)");
		HSSFCell c8 = createCell(book, customRow, (short) 8, "出库单据(张)");
		HSSFCell c9 = createCell(book, customRow, (short) 9, "入出库单合计(张)");

		c0.setCellStyle(cStyleM);
		c1.setCellStyle(cStyleM);
		c2.setCellStyle(cStyleM);
		c3.setCellStyle(cStyleM);
		c4.setCellStyle(cStyleM);
		c5.setCellStyle(cStyleM);
		c6.setCellStyle(cStyleM);
		c7.setCellStyle(cStyleM);
		c8.setCellStyle(cStyleM);
		c9.setCellStyle(cStyleM);

		int size = list.size();

		// 统计单一仓库
		String balanceMode = "";
		double initMoney = 0;
		double inMoney = 0;
		double outMoney = 0;
		double inAndOutMoney = 0;
		double finalMoney = 0;
		int inBillCount = 0;
		int outBillCount = 0;
		int inAndOutBillCount = 0;

		// 统计所有仓库
		double initMoneyFinally = 0;
		double inMoneyFinally = 0;
		double outMoneyFinally = 0;
		double inAndOutMoneyFinally = 0;
		double finalMoneyFinally = 0;
		int inBillCountFinally = 0;
		int outBillCountFinally = 0;
		int inAndOutBillCountFinally = 0;

		// 统计所有仓库压库数据
		double initMoneyFinallyYK = 0;
		double inMoneyFinallyYK = 0;
		double outMoneyFinallyYK = 0;
		double inAndOutMoneyFinallyYK = 0;
		double finalMoneyFinallyYK = 0;
		int inBillCountFinallyYK = 0;
		int outBillCountFinallyYK = 0;
		int inAndOutBillCountFinallyYK = 0;

		// 统计所有仓库买断数据
		double initMoneyFinallyMD = 0;
		double inMoneyFinallyMD = 0;
		double outMoneyFinallyMD = 0;
		double inAndOutMoneyFinallyMD = 0;
		double finalMoneyFinallyMD = 0;
		int inBillCountFinallyMD = 0;
		int outBillCountFinallyMD = 0;
		int inAndOutBillCountFinallyMD = 0;

		int index = 2;// 为实际数据生成创建行索引
		int rowSpanIndex = 2;// 合并仓库名称列所需要的行索引
		HSSFRow warehouseNameRow = null;// 用于保留合并仓库名称后设置仓库名称
		/**
		 * 提取数据 开始
		 * 在提取过程中,默认list的大小是偶数的,并且应该是(仓库数×2;"两种结算模式").如果今后结算模式发生变化.此报表须作调整
		 * 所以,在上述条件情况,数据提取做出针对性的设计.即:每次提取一个仓库的所有结算模式数据(每次两条).然后做数据处理.
		 */
		for (int i = 0; i < size; i++) {
			Map map1 = (Map) list.get(i);// 获取当前行
			Map map2 = null;
			String warehouseName1 = "";
			String warehouseName2 = "default value";

			warehouseName1 = (String) map1.get("NAME");
			if (i != size - 1) {
				map2 = (Map) list.get(i + 1);// 获取次行
				warehouseName2 = (String) map2.get("NAME");
			}

			// 获取当前行数据
			String balanceMode1 = Integer.parseInt((String) map1.get("BALANCE_MODE")) == 1 ? "压库" : "买断";
			double initMoney1 = Double.parseDouble((String) map1.get("INIT_MONEY"));
			double inMoney1 = Double.parseDouble((String) map1.get("IN_MONEY"));
			double outMoney1 = Double.parseDouble((String) map1.get("OUT_MONEY"));
			double inAndOutMoney1 = Double.parseDouble((String) map1.get("IN_AND_OUT_MONEY"));
			double finalMoney1 = Double.parseDouble((String) map1.get("FINAL_MONEY"));
			int inBillCount1 = Integer.parseInt((String) map1.get("IN_BILL_COUNT"));
			int outBillCount1 = Integer.parseInt((String) map1.get("OUT_BILL_COUNT"));
			int inAndOutBillCount1 = Integer.parseInt((String) map1.get("IN_AND_OUT_BILL_COUNT"));

			if (balanceMode1.equals("压库")) {
				initMoneyFinallyYK = initMoneyFinallyYK + initMoney1;
				inMoneyFinallyYK = inMoneyFinallyYK + inMoney1;
				outMoneyFinallyYK = outMoneyFinallyYK + outMoney1;
				inAndOutMoneyFinallyYK = inAndOutMoneyFinallyYK + inAndOutMoney1;
				finalMoneyFinallyYK = inAndOutMoneyFinallyYK + finalMoney1;
				inBillCountFinallyYK = inBillCountFinallyYK + inBillCount1;
				outBillCountFinallyYK = outBillCountFinallyYK + outBillCount1;
				inAndOutBillCountFinallyYK = inAndOutBillCountFinallyYK + inAndOutBillCount1;
			} else {
				initMoneyFinallyMD = initMoneyFinallyMD + initMoney1;
				inMoneyFinallyMD = inMoneyFinallyMD + inMoney1;
				outMoneyFinallyMD = outMoneyFinallyMD + outMoney1;
				inAndOutMoneyFinallyMD = inAndOutMoneyFinallyMD + inAndOutMoney1;
				finalMoneyFinallyMD = inAndOutMoneyFinallyMD + finalMoney1;
				inBillCountFinallyMD = inBillCountFinallyMD + inBillCount1;
				outBillCountFinallyMD = outBillCountFinallyMD + outBillCount1;
				inAndOutBillCountFinallyMD = inAndOutBillCountFinallyMD + inAndOutBillCount1;
			}

			// 合计当前仓库数据
			initMoney = initMoney + initMoney1;
			inMoney = inMoney + inMoney1;
			outMoney = outMoney + outMoney1;
			inAndOutMoney = inAndOutMoney + inAndOutMoney1;
			finalMoney = finalMoney + finalMoney1;
			inBillCount = inBillCount + inBillCount1;
			outBillCount = outBillCount + outBillCount1;
			inAndOutBillCount = inAndOutBillCount + inAndOutBillCount1;

			// 创建当前行数据
			HSSFRow row = sheet.createRow((short) index++);
			if (warehouseNameRow == null) {
				warehouseNameRow = row;// 保留每一个仓库的首行
			}
			// createCell(book, row, (short) 0, warehouseName1);
			createCell(book, row, (short) 1, balanceMode1);
			createCell(book, row, (short) 2, StringUtil.showPrice(String.valueOf(initMoney1)));
			createCell(book, row, (short) 3, StringUtil.showPrice(String.valueOf(inMoney1)));
			createCell(book, row, (short) 4, StringUtil.showPrice(String.valueOf(outMoney1)));
			createCell(book, row, (short) 5, StringUtil.showPrice(String.valueOf(inAndOutMoney1)));
			createCell(book, row, (short) 6, StringUtil.showPrice(String.valueOf(finalMoney1)));
			createCell(book, row, (short) 7, String.valueOf(inBillCount1));
			createCell(book, row, (short) 8, String.valueOf(outBillCount1));
			createCell(book, row, (short) 9, String.valueOf(inAndOutBillCount1));
			// 判断是否还属于同一仓库数据
			if (warehouseName1.equals(warehouseName2)) {
				// 仍属于同一仓库数据
				// 不生成合计
			} else {
				// 已经不属于同一仓库数据
				// 生成合计
				row = sheet.createRow((short) index++);
				Region rowSpan = new Region(rowSpanIndex, (short) 0, index - 1, (short) 0);// 合并仓库名称列
				sheet.addMergedRegion(rowSpan);
				HSSFCell warehouseCell = createCell(book, warehouseNameRow, (short) 0, warehouseName1);// 用保留下来的仓库首行来设置仓库名称
				warehouseCell.setCellStyle(cStyleM);// 设置仓库名称样式
				HSSFCell cell = createCell(book, row, (short) 1, "合计");
				cell.setEncoding(HSSFCell.ENCODING_UTF_16);
				createCell(book, row, (short) 2, StringUtil.showPrice(String.valueOf(initMoney)));
				createCell(book, row, (short) 3, StringUtil.showPrice(String.valueOf(inMoney)));
				createCell(book, row, (short) 4, StringUtil.showPrice(String.valueOf(outMoney)));
				createCell(book, row, (short) 5, StringUtil.showPrice(String.valueOf(inAndOutMoney)));
				createCell(book, row, (short) 6, StringUtil.showPrice(String.valueOf(finalMoney)));
				createCell(book, row, (short) 7, String.valueOf(inBillCount));
				createCell(book, row, (short) 8, String.valueOf(outBillCount));
				createCell(book, row, (short) 9, String.valueOf(inAndOutBillCount));

				// 累计本仓库数据
				initMoneyFinally = initMoneyFinally + initMoney;
				inMoneyFinally = inMoneyFinally + inMoney;
				outMoneyFinally = outMoneyFinally + outMoney;
				inAndOutMoneyFinally = inAndOutMoneyFinally + inAndOutMoney;
				finalMoneyFinally = inAndOutMoneyFinally + finalMoney;
				inBillCountFinally = inBillCountFinally + inBillCount;
				outBillCountFinally = outBillCountFinally + outBillCount;
				inAndOutBillCountFinally = inAndOutBillCountFinally + inAndOutBillCount;

				// 单一仓库合计归零
				initMoney = 0;
				inMoney = 0;
				outMoney = 0;
				inAndOutMoney = 0;
				finalMoney = 0;
				inBillCount = 0;
				outBillCount = 0;
				inAndOutBillCount = 0;
				rowSpanIndex = index;
				warehouseNameRow = null;
			}
		}

		HSSFRow row = sheet.createRow((short) index++);
		Region lastSpan = new Region(index - 1, (short) 0, index - 1, (short) 1);// 合并最后一行
		sheet.addMergedRegion(lastSpan);
		createCell(book, row, (short) 0, "压库合计");
		createCell(book, row, (short) 2, StringUtil.showPrice(String.valueOf(initMoneyFinallyYK)));
		createCell(book, row, (short) 3, StringUtil.showPrice(String.valueOf(inMoneyFinallyYK)));
		createCell(book, row, (short) 4, StringUtil.showPrice(String.valueOf(outMoneyFinallyYK)));
		createCell(book, row, (short) 5, StringUtil.showPrice(String.valueOf(inAndOutMoneyFinallyYK)));
		createCell(book, row, (short) 6, StringUtil.showPrice(String.valueOf(finalMoneyFinallyYK)));
		createCell(book, row, (short) 7, String.valueOf(inBillCountFinallyYK));
		createCell(book, row, (short) 8, String.valueOf(outBillCountFinallyYK));
		createCell(book, row, (short) 9, String.valueOf(inAndOutBillCountFinallyYK));

		row = sheet.createRow((short) index++);
		lastSpan = new Region(index - 1, (short) 0, index - 1, (short) 1);// 合并最后一行
		sheet.addMergedRegion(lastSpan);
		createCell(book, row, (short) 0, "买断合计");
		createCell(book, row, (short) 2, StringUtil.showPrice(String.valueOf(initMoneyFinallyMD)));
		createCell(book, row, (short) 3, StringUtil.showPrice(String.valueOf(inMoneyFinallyMD)));
		createCell(book, row, (short) 4, StringUtil.showPrice(String.valueOf(outMoneyFinallyMD)));
		createCell(book, row, (short) 5, StringUtil.showPrice(String.valueOf(inAndOutMoneyFinallyMD)));
		createCell(book, row, (short) 6, StringUtil.showPrice(String.valueOf(finalMoneyFinallyMD)));
		createCell(book, row, (short) 7, String.valueOf(inBillCountFinallyMD));
		createCell(book, row, (short) 8, String.valueOf(outBillCountFinallyMD));
		createCell(book, row, (short) 9, String.valueOf(inAndOutBillCountFinallyMD));

		customRow = sheet.createRow((short) index++);
		lastSpan = new Region(index - 1, (short) 0, index - 1, (short) 1);// 合并最后一行
		sheet.addMergedRegion(lastSpan);
		HSSFCell cell_0 = createCell(book, customRow, (short) 0, "合计:");
		HSSFCell cell_2 = createCell(book, customRow, (short) 2, StringUtil.showPrice(String.valueOf(initMoneyFinally)));
		HSSFCell cell_3 = createCell(book, customRow, (short) 3, StringUtil.showPrice(String.valueOf(inMoneyFinally)));
		HSSFCell cell_4 = createCell(book, customRow, (short) 4, StringUtil.showPrice(String.valueOf(outMoneyFinally)));
		HSSFCell cell_5 = createCell(book, customRow, (short) 5, StringUtil.showPrice(String.valueOf(inAndOutMoneyFinally)));
		HSSFCell cell_6 = createCell(book, customRow, (short) 6, StringUtil.showPrice(String.valueOf(finalMoneyFinally)));
		HSSFCell cell_7 = createCell(book, customRow, (short) 7, String.valueOf(inBillCountFinally));
		HSSFCell cell_8 = createCell(book, customRow, (short) 8, String.valueOf(outBillCountFinally));
		HSSFCell cell_9 = createCell(book, customRow, (short) 9, String.valueOf(inAndOutBillCountFinally));

		cell_0.setCellStyle(cStyleM_R);
		cell_2.setCellStyle(cStyleM_R);
		cell_3.setCellStyle(cStyleM_R);
		cell_4.setCellStyle(cStyleM_R);
		cell_5.setCellStyle(cStyleM_R);
		cell_6.setCellStyle(cStyleM_R);
		cell_7.setCellStyle(cStyleM_R);
		cell_8.setCellStyle(cStyleM_R);
		cell_9.setCellStyle(cStyleM_R);
		/* 提取数据 结束 */

		fileName = fileName + ".xls";
		response.setHeader("Cache-Control", "No-cache");
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
		response.setDateHeader("Expires", 0);
		response.setContentType("application/ms-excel");
		response.addHeader("Content-disposition", "filename=" + fileName);
		ServletOutputStream out = null;
		out = response.getOutputStream();
		book.write(out);
		out.flush();
		out.close();
	}

	/**
	 * 报表8 买断产品资金进出累计汇总（账本分类）
	 * 
	 * @param aList
	 * @param title
	 * @param start
	 * @param end
	 */
	private void writeExcel_ReportMDWCMoneyInout(List vec, String month, String warehouseCode, String fileName, String start, String end,
			HttpServletRequest request, HttpServletResponse response) {
		DBConnection con = null;
		ServletOutputStream out = null;
		boolean parent = false;
		/* 循环形参vec 结构<List>(1:String[2],2.3.4...:String[15]) */
		int size;
		if (vec == null) {
			size = 0;
		} else {
			size = vec.size();
		}
		HSSFWorkbook tWb = new HSSFWorkbook();
		HSSFSheet tSheet = null;
		try {
			for (int k = 0; k < size; k++) {
				List list = (List) vec.get(k);
				String[] warehouseObject = (String[]) list.get(0);
				String name = warehouseObject[1] + "(" + warehouseObject[0] + ")";
				tSheet = tWb.createSheet();
				HSSFRow tRow = null;
				Region region = null;
				tSheet.setColumnWidth((short) 0, (short) (16 * 256));
				tSheet.setColumnWidth((short) 1, (short) (12 * 256));
				tSheet.setColumnWidth((short) 2, (short) (12 * 256));
				tSheet.setColumnWidth((short) 3, (short) (18 * 256));
				tSheet.setColumnWidth((short) 4, (short) (10 * 256));
				tSheet.setColumnWidth((short) 5, (short) (10 * 256));
				tSheet.setColumnWidth((short) 6, (short) (10 * 256));
				tSheet.setColumnWidth((short) 7, (short) (10 * 256));
				tSheet.setColumnWidth((short) 8, (short) (12 * 256));
				tSheet.setColumnWidth((short) 9, (short) (14 * 256));
				tSheet.setColumnWidth((short) 10, (short) (14 * 256));
				tSheet.setColumnWidth((short) 11, (short) (14 * 256));
				tSheet.setColumnWidth((short) 12, (short) (14 * 256));
				tSheet.setColumnWidth((short) 13, (short) (14 * 256));
				tWb.setSheetName(k, name, HSSFCell.ENCODING_UTF_16);
				HSSFFont font = tWb.createFont();
				font.setFontHeightInPoints((short) 9);
				font.setFontName("宋体");
				font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
				HSSFCellStyle cStyle = tWb.createCellStyle();
				cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
				HSSFCellStyle cStyleM = tWb.createCellStyle();
				cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
				cStyleM.setFont(font);

				HSSFCellStyle cStyleM_R = tWb.createCellStyle();
				cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
				cStyleM_R.setFont(font);
				// 标题行
				tRow = tSheet.createRow((short) 0);
				HSSFCell c0 = createCell(tWb, tRow, (short) 4, name + "仓库买断产品资金进出累计汇总(账本分类)");
				c0.setCellStyle(cStyleM);
				// 日期行
				tRow = tSheet.createRow((short) 1);
				region = new Region(1, (short) 4, 1, (short) 8);
				tSheet.addMergedRegion(region);
				createCell(tWb, tRow, (short) 4, "统计日期:" + start + " 至 " + end, HSSFCellStyle.ALIGN_CENTER, false);
				// 表头行
				tRow = tSheet.createRow((short) 2);
				HSSFCell c1 = createCell(tWb, tRow, (short) 0, "产品类别");
				HSSFCell c2 = createCell(tWb, tRow, (short) 1, "期初金额");
				HSSFCell c3 = createCell(tWb, tRow, (short) 2, "购入");
				HSSFCell c4 = createCell(tWb, tRow, (short) 3, "盘盈");
				HSSFCell c5 = createCell(tWb, tRow, (short) 4, "入库合计");
				HSSFCell c6 = createCell(tWb, tRow, (short) 5, "领用");
				HSSFCell c7 = createCell(tWb, tRow, (short) 6, "盘亏");
				HSSFCell c8 = createCell(tWb, tRow, (short) 7, "出库合计");
				HSSFCell c9 = createCell(tWb, tRow, (short) 8, "结存");
				c1.setCellStyle(cStyleM_R);
				c2.setCellStyle(cStyleM_R);
				c3.setCellStyle(cStyleM_R);
				c4.setCellStyle(cStyleM_R);
				c5.setCellStyle(cStyleM_R);
				c6.setCellStyle(cStyleM_R);
				c7.setCellStyle(cStyleM_R);
				c8.setCellStyle(cStyleM_R);
				c9.setCellStyle(cStyleM_R);
				short index = 2; // 当前所在行号

				/** 总信息 */
				double totalMonthMoney = 0;
				double totalInMoney1 = 0;
				double totalInMoney2 = 0;
				double totalAllInMoney = 0;
				double totalOutMoney1 = 0;
				double totalOutMoney2 = 0;
				double totalAllOutMoney = 0;
				double totalMoney = 0;

				con = DBConnection.open(false);
				List newVec = splitWarehouseCategory(list);
				// 缺少为空验证
				int sizeAll = newVec.size();
				// 总集合
				for (int i = 0; i < sizeAll; i++) {
					List subVec = (List) newVec.get(i);
					int sizeSub = subVec.size();
					// 子类集合
					WarehouseCategory wc = null;

					/** 小记信息 */
					double monthMoneyCateCount = 0;
					double productInMoney1CateCount = 0;
					double productInMoney2CateCount = 0;
					double productInMoney3CateCount = 0;
					double productOutMoney1CateCount = 0;
					double productOutMoney2CateCount = 0;
					double productOutMoney3CateCount = 0;
					double allMoneyCateCount = 0;

					for (int j = 0; j < sizeSub; j++) {

						/** 行信息 */
						double monthMoney = 0;
						double productInMoney1 = 0;
						double productInMoney2 = 0;
						double productInMoney3 = 0;
						double productOutMoney1 = 0;
						double productOutMoney2 = 0;
						double productOutMoney3 = 0;
						double allMoney = 0;
						// 缺少为空验证
						// 单一行
						String[] values = (String[]) subVec.get(j);
						if (j == 0) {
							if (values[13].equals("0")) {
								parent = false;
							} else {
								wc = WarehouseCategory.fetchbyCode(con, values[13], warehouseObject[0]);
								parent = true;
							}
						}
						monthMoney = Double.parseDouble(values[2]);
						productInMoney1 = Double.parseDouble(values[4]);
						productInMoney2 = Double.parseDouble(values[5]);
						productInMoney3 = Double.parseDouble(values[6]);
						productOutMoney1 = Double.parseDouble(values[8]);
						productOutMoney2 = Double.parseDouble(values[9]);
						productOutMoney3 = Double.parseDouble(values[10]);
						allMoney = Double.parseDouble(values[12]);

						tRow = tSheet.createRow((short) (index + 1));
						createCell(tWb, tRow, (short) 0, values[14]);
						createCell(tWb, tRow, (short) 1, StringUtil.showPrice(String.valueOf(monthMoney)));
						createCell(tWb, tRow, (short) 2, StringUtil.showPrice(String.valueOf(productInMoney1)));
						createCell(tWb, tRow, (short) 3, StringUtil.showPrice(String.valueOf(productInMoney2)));
						createCell(tWb, tRow, (short) 4, StringUtil.showPrice(String.valueOf(productInMoney3)));
						createCell(tWb, tRow, (short) 5, StringUtil.showPrice(String.valueOf(productOutMoney1)));
						createCell(tWb, tRow, (short) 6, StringUtil.showPrice(String.valueOf(productOutMoney2)));
						createCell(tWb, tRow, (short) 7, StringUtil.showPrice(String.valueOf(productOutMoney3)));
						createCell(tWb, tRow, (short) 8, StringUtil.showPrice(String.valueOf(allMoney)));

						monthMoneyCateCount += monthMoney;
						productInMoney1CateCount += productInMoney1;
						productInMoney2CateCount += productInMoney2;
						productInMoney3CateCount += productInMoney3;
						productOutMoney1CateCount += productOutMoney1;
						productOutMoney2CateCount += productOutMoney2;
						productOutMoney3CateCount += productOutMoney3;
						allMoneyCateCount += allMoney;

						index++;
						if (j + 1 == sizeSub) {
							tRow = tSheet.createRow((short) (index + 1));
							if (parent == true) {
								HSSFCell zongjiCell = tRow.createCell((short) 0);
								HSSFCell cell_1 = tRow.createCell((short) 1);
								HSSFCell cell_2 = tRow.createCell((short) 2);
								HSSFCell cell_3 = tRow.createCell((short) 3);
								HSSFCell cell_4 = tRow.createCell((short) 4);
								HSSFCell cell_5 = tRow.createCell((short) 5);
								HSSFCell cell_6 = tRow.createCell((short) 6);
								HSSFCell cell_7 = tRow.createCell((short) 7);
								HSSFCell cell_8 = tRow.createCell((short) 8);

								zongjiCell.setCellStyle(cStyleM_R);
								cell_1.setCellStyle(cStyleM_R);
								cell_2.setCellStyle(cStyleM_R);
								cell_3.setCellStyle(cStyleM_R);
								cell_4.setCellStyle(cStyleM_R);
								cell_5.setCellStyle(cStyleM_R);
								cell_6.setCellStyle(cStyleM_R);
								cell_7.setCellStyle(cStyleM_R);
								cell_8.setCellStyle(cStyleM_R);

								zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);

								zongjiCell.setCellValue(wc.getCategoryName() + "    小计:");
								cell_1.setCellValue(StringUtil.showPrice(String.valueOf(monthMoneyCateCount)));
								cell_2.setCellValue(StringUtil.showPrice(String.valueOf(productInMoney1CateCount)));
								cell_3.setCellValue(StringUtil.showPrice(String.valueOf(productInMoney2CateCount)));
								cell_4.setCellValue(StringUtil.showPrice(String.valueOf(productInMoney3CateCount)));
								cell_5.setCellValue(StringUtil.showPrice(String.valueOf(productOutMoney1CateCount)));
								cell_6.setCellValue(StringUtil.showPrice(String.valueOf(productOutMoney2CateCount)));
								cell_7.setCellValue(StringUtil.showPrice(String.valueOf(productOutMoney3CateCount)));
								cell_8.setCellValue(StringUtil.showPrice(String.valueOf(allMoneyCateCount)));
							}
							totalMonthMoney += monthMoneyCateCount;
							totalInMoney1 += productInMoney1CateCount;
							totalInMoney2 += productInMoney2CateCount;
							totalAllInMoney += productInMoney3CateCount;
							totalOutMoney1 += productOutMoney1CateCount;
							totalOutMoney2 += productOutMoney2CateCount;
							totalAllOutMoney += productOutMoney3CateCount;
							totalMoney += allMoneyCateCount;
							index++;
						}
					}
				}

				// 总计行
				if (index > 2) {
					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell zongjiCell = tRow.createCell((short) 0);
					HSSFCell cell_1 = tRow.createCell((short) 1);
					HSSFCell cell_2 = tRow.createCell((short) 2);
					HSSFCell cell_3 = tRow.createCell((short) 3);
					HSSFCell cell_4 = tRow.createCell((short) 4);
					HSSFCell cell_5 = tRow.createCell((short) 5);
					HSSFCell cell_6 = tRow.createCell((short) 6);
					HSSFCell cell_7 = tRow.createCell((short) 7);
					HSSFCell cell_8 = tRow.createCell((short) 8);

					zongjiCell.setCellStyle(cStyleM_R);
					cell_1.setCellStyle(cStyleM_R);
					cell_2.setCellStyle(cStyleM_R);
					cell_3.setCellStyle(cStyleM_R);
					cell_4.setCellStyle(cStyleM_R);
					cell_5.setCellStyle(cStyleM_R);
					cell_6.setCellStyle(cStyleM_R);
					cell_7.setCellStyle(cStyleM_R);
					cell_8.setCellStyle(cStyleM_R);

					zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);

					zongjiCell.setCellValue("合计：");
					cell_1.setCellValue(StringUtil.showPrice(String.valueOf(totalMonthMoney)));
					cell_2.setCellValue(StringUtil.showPrice(String.valueOf(totalInMoney1)));
					cell_3.setCellValue(StringUtil.showPrice(String.valueOf(totalInMoney2)));
					cell_4.setCellValue(StringUtil.showPrice(String.valueOf(totalAllInMoney)));
					cell_5.setCellValue(StringUtil.showPrice(String.valueOf(totalOutMoney1)));
					cell_6.setCellValue(StringUtil.showPrice(String.valueOf(totalOutMoney2)));
					cell_7.setCellValue(StringUtil.showPrice(String.valueOf(totalAllOutMoney)));
					cell_8.setCellValue(StringUtil.showPrice(String.valueOf(totalMoney)));

				}
			}
			fileName = fileName + ".xls";
			response.setHeader("Cache-Control", "No-cache");
			response.setHeader("Pragma", "No-cache");
			response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
			response.setDateHeader("Expires", 0);
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();

			tWb.write(out);

			out.flush();
			out.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {
				if (con != null) {
					con.close();
				}
				if (out != null) {
					out.close();
				}
			} catch (Exception ex1) {

			}
		}
	}

	private void writeExcel_ReportWCMoneyInout(List vec, String month, String warehouseCode, String fileName, String start, String end,
			HttpServletRequest request, HttpServletResponse response) {
		DBConnection con = null;
		ServletOutputStream out = null;
		boolean parent = false;
		/* 循环形参vec 结构<List>(1:String[2],2.3.4...:String[15]) */
		int size;
		if (vec == null) {
			size = 0;
		} else {
			size = vec.size();
		}
		HSSFWorkbook tWb = new HSSFWorkbook();
		HSSFSheet tSheet = null;
		try {
			for (int k = 0; k < size; k++) {
				List list = (List) vec.get(k);
				String[] warehouseObject = (String[]) list.get(0);
				String name = warehouseObject[1] + "(" + warehouseObject[0] + ")";
				tSheet = tWb.createSheet();
				HSSFRow tRow = null;
				Region region = null;
				tSheet.setColumnWidth((short) 0, (short) (16 * 256));
				tSheet.setColumnWidth((short) 1, (short) (12 * 256));
				tSheet.setColumnWidth((short) 2, (short) (12 * 256));
				tSheet.setColumnWidth((short) 3, (short) (18 * 256));
				tSheet.setColumnWidth((short) 4, (short) (10 * 256));
				tSheet.setColumnWidth((short) 5, (short) (10 * 256));
				tSheet.setColumnWidth((short) 6, (short) (10 * 256));
				tSheet.setColumnWidth((short) 7, (short) (10 * 256));
				tSheet.setColumnWidth((short) 8, (short) (12 * 256));
				tSheet.setColumnWidth((short) 9, (short) (14 * 256));
				tSheet.setColumnWidth((short) 10, (short) (14 * 256));
				tSheet.setColumnWidth((short) 11, (short) (14 * 256));
				tSheet.setColumnWidth((short) 12, (short) (14 * 256));
				tSheet.setColumnWidth((short) 13, (short) (14 * 256));
				tWb.setSheetName(k, name, HSSFCell.ENCODING_UTF_16);
				HSSFFont font = tWb.createFont();
				font.setFontHeightInPoints((short) 9);
				font.setFontName("宋体");
				font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
				HSSFCellStyle cStyle = tWb.createCellStyle();
				cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
				HSSFCellStyle cStyleM = tWb.createCellStyle();
				cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
				cStyleM.setFont(font);

				HSSFCellStyle cStyleM_R = tWb.createCellStyle();
				cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
				cStyleM_R.setFont(font);
				// 标题行
				tRow = tSheet.createRow((short) 0);
				HSSFCell c0 = createCell(tWb, tRow, (short) 4, name + "仓库产品资金进出累计汇总(仓库分类)");
				c0.setCellStyle(cStyleM);
				// 日期行
				tRow = tSheet.createRow((short) 1);
				region = new Region(1, (short) 4, 1, (short) 8);
				tSheet.addMergedRegion(region);
				createCell(tWb, tRow, (short) 4, "统计日期:" + start + " 至 " + end, HSSFCellStyle.ALIGN_CENTER, false);
				// 表头行
				tRow = tSheet.createRow((short) 2);
				HSSFCell c1 = createCell(tWb, tRow, (short) 0, "产品类别");
				HSSFCell c2 = createCell(tWb, tRow, (short) 1, "期初金额");
				HSSFCell c3 = createCell(tWb, tRow, (short) 2, "购入");
				HSSFCell c4 = createCell(tWb, tRow, (short) 3, "盘盈");
				HSSFCell c5 = createCell(tWb, tRow, (short) 4, "入库合计");
				HSSFCell c6 = createCell(tWb, tRow, (short) 5, "领用");
				HSSFCell c7 = createCell(tWb, tRow, (short) 6, "盘亏");
				HSSFCell c8 = createCell(tWb, tRow, (short) 7, "出库合计");
				HSSFCell c9 = createCell(tWb, tRow, (short) 8, "结存");
				c1.setCellStyle(cStyleM_R);
				c2.setCellStyle(cStyleM_R);
				c3.setCellStyle(cStyleM_R);
				c4.setCellStyle(cStyleM_R);
				c5.setCellStyle(cStyleM_R);
				c6.setCellStyle(cStyleM_R);
				c7.setCellStyle(cStyleM_R);
				c8.setCellStyle(cStyleM_R);
				c9.setCellStyle(cStyleM_R);
				short index = 2; // 当前所在行号

				/** 总信息 */
				double totalMonthMoney = 0;
				double totalInMoney1 = 0;
				double totalInMoney2 = 0;
				double totalAllInMoney = 0;
				double totalOutMoney1 = 0;
				double totalOutMoney2 = 0;
				double totalAllOutMoney = 0;
				double totalMoney = 0;

				con = DBConnection.open(false);
				List newVec = splitWarehouseCategory(list);
				// 缺少为空验证
				int sizeAll = newVec.size();
				// 总集合
				for (int i = 0; i < sizeAll; i++) {
					List subVec = (List) newVec.get(i);
					int sizeSub = subVec.size();
					// 子类集合
					WarehouseCategory wc = null;

					/** 小记信息 */
					double monthMoneyCateCount = 0;
					double productInMoney1CateCount = 0;
					double productInMoney2CateCount = 0;
					double productInMoney3CateCount = 0;
					double productOutMoney1CateCount = 0;
					double productOutMoney2CateCount = 0;
					double productOutMoney3CateCount = 0;
					double allMoneyCateCount = 0;

					for (int j = 0; j < sizeSub; j++) {

						/** 行信息 */
						double monthMoney = 0;
						double productInMoney1 = 0;
						double productInMoney2 = 0;
						double productInMoney3 = 0;
						double productOutMoney1 = 0;
						double productOutMoney2 = 0;
						double productOutMoney3 = 0;
						double allMoney = 0;
						// 缺少为空验证
						// 单一行
						String[] values = (String[]) subVec.get(j);
						if (j == 0) {
							if (values[13].equals("0")) {
								parent = false;
							} else {
								wc = WarehouseCategory.fetchbyLikeCode(con, values[13], warehouseObject[0]);
								parent = true;
							}
						}
						monthMoney = Double.parseDouble(values[2]);
						productInMoney1 = Double.parseDouble(values[4]);
						productInMoney2 = Double.parseDouble(values[5]);
						productInMoney3 = Double.parseDouble(values[6]);
						productOutMoney1 = Double.parseDouble(values[8]);
						productOutMoney2 = Double.parseDouble(values[9]);
						productOutMoney3 = Double.parseDouble(values[10]);
						allMoney = Double.parseDouble(values[12]);

						tRow = tSheet.createRow((short) (index + 1));
						createCell(tWb, tRow, (short) 0, values[14]);
						createCell(tWb, tRow, (short) 1, StringUtil.showPrice(String.valueOf(monthMoney)));
						createCell(tWb, tRow, (short) 2, StringUtil.showPrice(String.valueOf(productInMoney1)));
						createCell(tWb, tRow, (short) 3, StringUtil.showPrice(String.valueOf(productInMoney2)));
						createCell(tWb, tRow, (short) 4, StringUtil.showPrice(String.valueOf(productInMoney3)));
						createCell(tWb, tRow, (short) 5, StringUtil.showPrice(String.valueOf(productOutMoney1)));
						createCell(tWb, tRow, (short) 6, StringUtil.showPrice(String.valueOf(productOutMoney2)));
						createCell(tWb, tRow, (short) 7, StringUtil.showPrice(String.valueOf(productOutMoney3)));
						createCell(tWb, tRow, (short) 8, StringUtil.showPrice(String.valueOf(allMoney)));

						monthMoneyCateCount += monthMoney;
						productInMoney1CateCount += productInMoney1;
						productInMoney2CateCount += productInMoney2;
						productInMoney3CateCount += productInMoney3;
						productOutMoney1CateCount += productOutMoney1;
						productOutMoney2CateCount += productOutMoney2;
						productOutMoney3CateCount += productOutMoney3;
						allMoneyCateCount += allMoney;

						index++;
						if (j + 1 == sizeSub) {
							tRow = tSheet.createRow((short) (index + 1));
							if (parent == true) {
								HSSFCell zongjiCell = tRow.createCell((short) 0);
								HSSFCell cell_1 = tRow.createCell((short) 1);
								HSSFCell cell_2 = tRow.createCell((short) 2);
								HSSFCell cell_3 = tRow.createCell((short) 3);
								HSSFCell cell_4 = tRow.createCell((short) 4);
								HSSFCell cell_5 = tRow.createCell((short) 5);
								HSSFCell cell_6 = tRow.createCell((short) 6);
								HSSFCell cell_7 = tRow.createCell((short) 7);
								HSSFCell cell_8 = tRow.createCell((short) 8);

								zongjiCell.setCellStyle(cStyleM_R);
								cell_1.setCellStyle(cStyleM_R);
								cell_2.setCellStyle(cStyleM_R);
								cell_3.setCellStyle(cStyleM_R);
								cell_4.setCellStyle(cStyleM_R);
								cell_5.setCellStyle(cStyleM_R);
								cell_6.setCellStyle(cStyleM_R);
								cell_7.setCellStyle(cStyleM_R);
								cell_8.setCellStyle(cStyleM_R);

								zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);

								zongjiCell.setCellValue(wc.getCategoryName() + "    小计:");
								cell_1.setCellValue(StringUtil.showPrice(String.valueOf(monthMoneyCateCount)));
								cell_2.setCellValue(StringUtil.showPrice(String.valueOf(productInMoney1CateCount)));
								cell_3.setCellValue(StringUtil.showPrice(String.valueOf(productInMoney2CateCount)));
								cell_4.setCellValue(StringUtil.showPrice(String.valueOf(productInMoney3CateCount)));
								cell_5.setCellValue(StringUtil.showPrice(String.valueOf(productOutMoney1CateCount)));
								cell_6.setCellValue(StringUtil.showPrice(String.valueOf(productOutMoney2CateCount)));
								cell_7.setCellValue(StringUtil.showPrice(String.valueOf(productOutMoney3CateCount)));
								cell_8.setCellValue(StringUtil.showPrice(String.valueOf(allMoneyCateCount)));
							}
							totalMonthMoney += monthMoneyCateCount;
							totalInMoney1 += productInMoney1CateCount;
							totalInMoney2 += productInMoney2CateCount;
							totalAllInMoney += productInMoney3CateCount;
							totalOutMoney1 += productOutMoney1CateCount;
							totalOutMoney2 += productOutMoney2CateCount;
							totalAllOutMoney += productOutMoney3CateCount;
							totalMoney += allMoneyCateCount;
							index++;
						}
					}
				}

				// 总计行
				if (index > 2) {
					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell zongjiCell = tRow.createCell((short) 0);
					HSSFCell cell_1 = tRow.createCell((short) 1);
					HSSFCell cell_2 = tRow.createCell((short) 2);
					HSSFCell cell_3 = tRow.createCell((short) 3);
					HSSFCell cell_4 = tRow.createCell((short) 4);
					HSSFCell cell_5 = tRow.createCell((short) 5);
					HSSFCell cell_6 = tRow.createCell((short) 6);
					HSSFCell cell_7 = tRow.createCell((short) 7);
					HSSFCell cell_8 = tRow.createCell((short) 8);

					zongjiCell.setCellStyle(cStyleM_R);
					cell_1.setCellStyle(cStyleM_R);
					cell_2.setCellStyle(cStyleM_R);
					cell_3.setCellStyle(cStyleM_R);
					cell_4.setCellStyle(cStyleM_R);
					cell_5.setCellStyle(cStyleM_R);
					cell_6.setCellStyle(cStyleM_R);
					cell_7.setCellStyle(cStyleM_R);
					cell_8.setCellStyle(cStyleM_R);

					zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);

					zongjiCell.setCellValue("合计：");
					cell_1.setCellValue(StringUtil.showPrice(String.valueOf(totalMonthMoney)));
					cell_2.setCellValue(StringUtil.showPrice(String.valueOf(totalInMoney1)));
					cell_3.setCellValue(StringUtil.showPrice(String.valueOf(totalInMoney2)));
					cell_4.setCellValue(StringUtil.showPrice(String.valueOf(totalAllInMoney)));
					cell_5.setCellValue(StringUtil.showPrice(String.valueOf(totalOutMoney1)));
					cell_6.setCellValue(StringUtil.showPrice(String.valueOf(totalOutMoney2)));
					cell_7.setCellValue(StringUtil.showPrice(String.valueOf(totalAllOutMoney)));
					cell_8.setCellValue(StringUtil.showPrice(String.valueOf(totalMoney)));

				}
			}
			fileName = fileName + ".xls";
			response.setHeader("Cache-Control", "No-cache");
			response.setHeader("Pragma", "No-cache");
			response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
			response.setDateHeader("Expires", 0);
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();

			tWb.write(out);

			out.flush();
			out.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {
				if (con != null) {
					con.close();
				}
				if (out != null) {
					out.close();
				}
			} catch (Exception ex1) {

			}
		}
	}

	private void writeExcel_ReportPCMoneyInout(List vec, String month, String warehouseCode, String fileName, String start, String end,
			HttpServletRequest request, HttpServletResponse response) {
		DBConnection con = null;
		ServletOutputStream out = null;
		boolean parent = false;
		/* 循环形参vec 结构<List>(1:String[2],2.3.4...:String[15]) */
		int size;
		if (vec == null) {
			size = 0;
		} else {
			size = vec.size();
		}
		HSSFWorkbook tWb = new HSSFWorkbook();
		HSSFSheet tSheet = null;
		try {
			for (int k = 0; k < size; k++) {
				List list = (List) vec.get(k);
				String[] warehouseObject = (String[]) list.get(0);
				String name = warehouseObject[1] + "(" + warehouseObject[0] + ")";
				tSheet = tWb.createSheet();
				HSSFRow tRow = null;
				Region region = null;
				tSheet.setColumnWidth((short) 0, (short) (16 * 256));
				tSheet.setColumnWidth((short) 1, (short) (12 * 256));
				tSheet.setColumnWidth((short) 2, (short) (12 * 256));
				tSheet.setColumnWidth((short) 3, (short) (18 * 256));
				tSheet.setColumnWidth((short) 4, (short) (10 * 256));
				tSheet.setColumnWidth((short) 5, (short) (10 * 256));
				tSheet.setColumnWidth((short) 6, (short) (10 * 256));
				tSheet.setColumnWidth((short) 7, (short) (10 * 256));
				tSheet.setColumnWidth((short) 8, (short) (12 * 256));
				tSheet.setColumnWidth((short) 9, (short) (14 * 256));
				tSheet.setColumnWidth((short) 10, (short) (14 * 256));
				tSheet.setColumnWidth((short) 11, (short) (14 * 256));
				tSheet.setColumnWidth((short) 12, (short) (14 * 256));
				tSheet.setColumnWidth((short) 13, (short) (14 * 256));
				tWb.setSheetName(k, name, HSSFCell.ENCODING_UTF_16);
				HSSFFont font = tWb.createFont();
				font.setFontHeightInPoints((short) 9);
				font.setFontName("宋体");
				font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
				HSSFCellStyle cStyle = tWb.createCellStyle();
				cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
				HSSFCellStyle cStyleM = tWb.createCellStyle();
				cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
				cStyleM.setFont(font);

				HSSFCellStyle cStyleM_R = tWb.createCellStyle();
				cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
				cStyleM_R.setFont(font);
				// 标题行
				tRow = tSheet.createRow((short) 0);
				HSSFCell c0 = createCell(tWb, tRow, (short) 4, name + "仓库产品资金进出累计汇总(集团分类)");
				c0.setCellStyle(cStyleM);
				// 日期行
				tRow = tSheet.createRow((short) 1);
				region = new Region(1, (short) 4, 1, (short) 8);
				tSheet.addMergedRegion(region);
				createCell(tWb, tRow, (short) 4, "统计日期:" + start + " 至 " + end, HSSFCellStyle.ALIGN_CENTER, false);
				// 表头行
				tRow = tSheet.createRow((short) 2);
				HSSFCell c1 = createCell(tWb, tRow, (short) 0, "产品类别");
				HSSFCell c2 = createCell(tWb, tRow, (short) 1, "期初金额");
				HSSFCell c3 = createCell(tWb, tRow, (short) 2, "购入");
				HSSFCell c4 = createCell(tWb, tRow, (short) 3, "盘盈");
				HSSFCell c5 = createCell(tWb, tRow, (short) 4, "入库合计");
				HSSFCell c6 = createCell(tWb, tRow, (short) 5, "领用");
				HSSFCell c7 = createCell(tWb, tRow, (short) 6, "盘亏");
				HSSFCell c8 = createCell(tWb, tRow, (short) 7, "出库合计");
				HSSFCell c9 = createCell(tWb, tRow, (short) 8, "结存");
				c1.setCellStyle(cStyleM_R);
				c2.setCellStyle(cStyleM_R);
				c3.setCellStyle(cStyleM_R);
				c4.setCellStyle(cStyleM_R);
				c5.setCellStyle(cStyleM_R);
				c6.setCellStyle(cStyleM_R);
				c7.setCellStyle(cStyleM_R);
				c8.setCellStyle(cStyleM_R);
				c9.setCellStyle(cStyleM_R);
				short index = 2; // 当前所在行号

				/** 总信息 */
				double totalMonthMoney = 0;
				double totalInMoney1 = 0;
				double totalInMoney2 = 0;
				double totalAllInMoney = 0;
				double totalOutMoney1 = 0;
				double totalOutMoney2 = 0;
				double totalAllOutMoney = 0;
				double totalMoney = 0;

				con = DBConnection.open(false);
				List newVec = splitWarehouseCategory(list);
				// 缺少为空验证
				int sizeAll = newVec.size();
				// 总集合
				for (int i = 0; i < sizeAll; i++) {
					List subVec = (List) newVec.get(i);
					int sizeSub = subVec.size();
					// 子类集合
					ProductCategory wc = null;

					/** 小记信息 */
					double monthMoneyCateCount = 0;
					double productInMoney1CateCount = 0;
					double productInMoney2CateCount = 0;
					double productInMoney3CateCount = 0;
					double productOutMoney1CateCount = 0;
					double productOutMoney2CateCount = 0;
					double productOutMoney3CateCount = 0;
					double allMoneyCateCount = 0;

					for (int j = 0; j < sizeSub; j++) {

						/** 行信息 */
						double monthMoney = 0;
						double productInMoney1 = 0;
						double productInMoney2 = 0;
						double productInMoney3 = 0;
						double productOutMoney1 = 0;
						double productOutMoney2 = 0;
						double productOutMoney3 = 0;
						double allMoney = 0;
						// 缺少为空验证
						// 单一行
						String[] values = (String[]) subVec.get(j);
						if (j == 0) {
							if (values[13].equals("0") || values[13].equals("")) {
								parent = false;
							} else {
								wc = ProductCategory.fetchByCode(con, values[13]);
								parent = true;
							}
						}
						monthMoney = Double.parseDouble(values[2]);
						productInMoney1 = Double.parseDouble(values[4]);
						productInMoney2 = Double.parseDouble(values[5]);
						productInMoney3 = Double.parseDouble(values[6]);
						productOutMoney1 = Double.parseDouble(values[8]);
						productOutMoney2 = Double.parseDouble(values[9]);
						productOutMoney3 = Double.parseDouble(values[10]);
						allMoney = Double.parseDouble(values[12]);

						tRow = tSheet.createRow((short) (index + 1));
						createCell(tWb, tRow, (short) 0, values[14]);
						createCell(tWb, tRow, (short) 1, StringUtil.showPrice(String.valueOf(monthMoney)));
						createCell(tWb, tRow, (short) 2, StringUtil.showPrice(String.valueOf(productInMoney1)));
						createCell(tWb, tRow, (short) 3, StringUtil.showPrice(String.valueOf(productInMoney2)));
						createCell(tWb, tRow, (short) 4, StringUtil.showPrice(String.valueOf(productInMoney3)));
						createCell(tWb, tRow, (short) 5, StringUtil.showPrice(String.valueOf(productOutMoney1)));
						createCell(tWb, tRow, (short) 6, StringUtil.showPrice(String.valueOf(productOutMoney2)));
						createCell(tWb, tRow, (short) 7, StringUtil.showPrice(String.valueOf(productOutMoney3)));
						createCell(tWb, tRow, (short) 8, StringUtil.showPrice(String.valueOf(allMoney)));

						monthMoneyCateCount += monthMoney;
						productInMoney1CateCount += productInMoney1;
						productInMoney2CateCount += productInMoney2;
						productInMoney3CateCount += productInMoney3;
						productOutMoney1CateCount += productOutMoney1;
						productOutMoney2CateCount += productOutMoney2;
						productOutMoney3CateCount += productOutMoney3;
						allMoneyCateCount += allMoney;

						index++;
						if (j + 1 == sizeSub) {
							tRow = tSheet.createRow((short) (index + 1));
							if (parent == true) {
								HSSFCell zongjiCell = tRow.createCell((short) 0);
								HSSFCell cell_1 = tRow.createCell((short) 1);
								HSSFCell cell_2 = tRow.createCell((short) 2);
								HSSFCell cell_3 = tRow.createCell((short) 3);
								HSSFCell cell_4 = tRow.createCell((short) 4);
								HSSFCell cell_5 = tRow.createCell((short) 5);
								HSSFCell cell_6 = tRow.createCell((short) 6);
								HSSFCell cell_7 = tRow.createCell((short) 7);
								HSSFCell cell_8 = tRow.createCell((short) 8);

								zongjiCell.setCellStyle(cStyleM_R);
								cell_1.setCellStyle(cStyleM_R);
								cell_2.setCellStyle(cStyleM_R);
								cell_3.setCellStyle(cStyleM_R);
								cell_4.setCellStyle(cStyleM_R);
								cell_5.setCellStyle(cStyleM_R);
								cell_6.setCellStyle(cStyleM_R);
								cell_7.setCellStyle(cStyleM_R);
								cell_8.setCellStyle(cStyleM_R);

								zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);

								zongjiCell.setCellValue(wc.getName() + "    小计:");
								cell_1.setCellValue(StringUtil.showPrice(String.valueOf(monthMoneyCateCount)));
								cell_2.setCellValue(StringUtil.showPrice(String.valueOf(productInMoney1CateCount)));
								cell_3.setCellValue(StringUtil.showPrice(String.valueOf(productInMoney2CateCount)));
								cell_4.setCellValue(StringUtil.showPrice(String.valueOf(productInMoney3CateCount)));
								cell_5.setCellValue(StringUtil.showPrice(String.valueOf(productOutMoney1CateCount)));
								cell_6.setCellValue(StringUtil.showPrice(String.valueOf(productOutMoney2CateCount)));
								cell_7.setCellValue(StringUtil.showPrice(String.valueOf(productOutMoney3CateCount)));
								cell_8.setCellValue(StringUtil.showPrice(String.valueOf(allMoneyCateCount)));
							}
							totalMonthMoney += monthMoneyCateCount;
							totalInMoney1 += productInMoney1CateCount;
							totalInMoney2 += productInMoney2CateCount;
							totalAllInMoney += productInMoney3CateCount;
							totalOutMoney1 += productOutMoney1CateCount;
							totalOutMoney2 += productOutMoney2CateCount;
							totalAllOutMoney += productOutMoney3CateCount;
							totalMoney += allMoneyCateCount;
							index++;
						}
					}
				}

				// 总计行
				if (index > 2) {
					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell zongjiCell = tRow.createCell((short) 0);
					HSSFCell cell_1 = tRow.createCell((short) 1);
					HSSFCell cell_2 = tRow.createCell((short) 2);
					HSSFCell cell_3 = tRow.createCell((short) 3);
					HSSFCell cell_4 = tRow.createCell((short) 4);
					HSSFCell cell_5 = tRow.createCell((short) 5);
					HSSFCell cell_6 = tRow.createCell((short) 6);
					HSSFCell cell_7 = tRow.createCell((short) 7);
					HSSFCell cell_8 = tRow.createCell((short) 8);

					zongjiCell.setCellStyle(cStyleM_R);
					cell_1.setCellStyle(cStyleM_R);
					cell_2.setCellStyle(cStyleM_R);
					cell_3.setCellStyle(cStyleM_R);
					cell_4.setCellStyle(cStyleM_R);
					cell_5.setCellStyle(cStyleM_R);
					cell_6.setCellStyle(cStyleM_R);
					cell_7.setCellStyle(cStyleM_R);
					cell_8.setCellStyle(cStyleM_R);

					zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);

					zongjiCell.setCellValue("合计：");
					cell_1.setCellValue(StringUtil.showPrice(String.valueOf(totalMonthMoney)));
					cell_2.setCellValue(StringUtil.showPrice(String.valueOf(totalInMoney1)));
					cell_3.setCellValue(StringUtil.showPrice(String.valueOf(totalInMoney2)));
					cell_4.setCellValue(StringUtil.showPrice(String.valueOf(totalAllInMoney)));
					cell_5.setCellValue(StringUtil.showPrice(String.valueOf(totalOutMoney1)));
					cell_6.setCellValue(StringUtil.showPrice(String.valueOf(totalOutMoney2)));
					cell_7.setCellValue(StringUtil.showPrice(String.valueOf(totalAllOutMoney)));
					cell_8.setCellValue(StringUtil.showPrice(String.valueOf(totalMoney)));

				}
			}
			fileName = fileName + ".xls";
			response.setHeader("Cache-Control", "No-cache");
			response.setHeader("Pragma", "No-cache");
			response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
			response.setDateHeader("Expires", 0);
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();

			tWb.write(out);

			out.flush();
			out.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {
				if (con != null) {
					con.close();
				}
				if (out != null) {
					out.close();
				}
			} catch (Exception ex1) {

			}
		}
	}

	/** 将总集合分割 以Warehouse_category_code为分隔条件 */
	private List splitWarehouseCategory(List vec) {
		if (vec == null || vec.size() == 0) {
			return null;
		}
		int allSize = vec.size();
		List newVec = new ArrayList();
		List splitVec = new ArrayList();
		boolean needNew = false;
		for (int i = 1; i < allSize; i++) {
			if (needNew) {
				splitVec = new Vector();
				needNew = false;
			}
			String[] values1 = (String[]) vec.get(i);
			String[] values2 = null;
			if (allSize != i + 1) {
				values2 = (String[]) vec.get(i + 1);
				String parentCode1 = values1[13];
				String parentCode2 = values2[13];
				splitVec.add(values1);
				if (!parentCode1.equals(parentCode2)) {
					// 告知创建新的集合
					needNew = true;
					newVec.add(splitVec);
				}
			} else {
				splitVec.add(values1);
				newVec.add(splitVec);
			}
		}
		return newVec;
	}

	/**
	 * 空调报表
	 */
	public void writeExcel_ReportAirSort(Map map, String sheetName, String month, String title, String warehouseCode, String fileName, String start,
			String end, HttpServletRequest request, HttpServletResponse response) {
		ServletOutputStream out = null;
		try {
			HSSFWorkbook tWb = new HSSFWorkbook();
			AirSortReportExcel excel = new AirSortReportExcel();
			excel.writeExcel_ReportAirSort(map, sheetName, month, title, warehouseCode, fileName, start, end, tWb);
			/** 输出EXCEL文件 开始 */
			fileName = fileName + ".xls";
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();
			tWb.write(out);
			/** 输出EXCEL文件 结束 */

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}

	/**
	 * 报表18调用 根据起始时间 得到入库单纪录中 符合条件的供应商列表
	 */
	public Vector detailqueryProviderGroupWithOutBalance_mode(String warehouseCode, String start, String end, String providerName, boolean needall) {
		boolean provider = !providerName.equals("") && providerName != null;// 供应商是否存在
		String providertrue = "select code,name from t_provider where name = '" + providerName + "'";
		String sqlStart = " select a.code,(select name from t_provider where t_provider.code = a.code) name from( ";
		String sqlInStart = " select " + " inhead.provider_code code, " + " inhead.provider_name name " + " from " + " t_in_head inhead, " + " t_in_sub insub "
		+ " where " + " inhead.in_bill_code = insub.in_bill_code " + " and " + " inhead.warehouse_code like '" + warehouseCode + "%' "+
		" and " + " insub.status = '1' ";
		String sqlInEnd = " group by inhead.provider_code,inhead.provider_name ";
		String inneedallfalse = " and inhead.in_time >= '" + start + "' " + " and " + " inhead.in_time <= '" + end + "' ";
		String sqlOutStart = " select " + " per.code code, " + " per.name name " + " from " + " t_out_head outhead, " + " t_out_sub outsub, "
		+ " t_provider per " + " where " + " outhead.out_bill_code = outsub.out_bill_code " + " and " + " outhead.warehouse_code like '"
		+ warehouseCode + "%' " + " and " + " outsub.status = '1' " + " and " + " per.code = outsub.provider_code ";

		String sqlOutEnd = " group by per.code,per.name ";
		String outneedallfalse = " and outhead.out_time >= '" + start + "' and outhead.out_time <= '" + end + "' ";
		String sqlEnd = " ) a group by code order by code ";
		String sql = "";
		if (needall) {// 需要所有数据
			if (provider) {
				sql = providertrue;
			} else {
				sql = sqlStart + sqlInStart + sqlInEnd + " union all " + sqlOutStart + sqlOutEnd + sqlEnd;
			}
		} else {// 不需要所有数据
			if (provider) {
				sql = providertrue;
			} else {
				sql = sqlStart + sqlInStart + inneedallfalse + sqlInEnd + " union all " + sqlOutStart + outneedallfalse + sqlOutEnd + sqlEnd;
			}
		}
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		DBResult dbrs = null;
		ResultSet row = null;
		Vector vec = new Vector();
		try {
			dbrs = DBEngine.doSelect(con, sql);
			row = dbrs.getRs();
			while (row.next()) {
				ProviderTemp pt = new ProviderTemp();
				pt.providerCode = row.getString(1);
				pt.ProviderName = row.getString(2);
				vec.add(pt);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				row.close();
				dbrs.clear();
				con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return vec;
	}

	private boolean isProcessContinue(HttpServletRequest request,HttpServletResponse response){
		String action = request.getParameter("action");

		if(IS_REPORT_PROCESSING.equalsIgnoreCase(action)){
			String val = request.getParameter("val");
			HttpSession session = request.getSession();
			Boolean isReportProcessing = (Boolean)session.getAttribute(IS_REPORT_PROCESSING);
			if(isReportProcessing == null){
				isReportProcessing = Boolean.FALSE;
			}
			String jsonString = "{result:" + isReportProcessing.booleanValue() + ",val:" + val +"}";
			ResponseUtils.renderJson(response, jsonString);
			return false;
		}else{
			return true;
		}
	}
	
	//报表19开始
	public ObjectList detailquery16Group(String warehouseCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.code provider_code " + "from " + "t_out_head a," + "t_out_sub b," +
		// "t_product c," +//修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " +
		// "and b.product_id = c.id " +
		// "and c.provider_code = d.code " + //修改供应商条件查询
		"and b.provider_code = d.code " + // 修改供应商条件查询
		"and a.warehouse_code like '" + warehouseCode + "%' " ;
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		sql += " group by d.code";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16Group error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {
			}
		}
		return mReturn;
	}
	
	
	public ObjectList detailquery16YKOut(String warehouseCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}
		sql = sql + "from " + "t_out_head a," + "t_out_sub b,"
		+ "t_product c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " + "and b.product_id = c.id " + "and b.provider_code = d.code "
		+ "and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') "  + "and b.balance_mode = '" + ConstDefine.STR_YK
		+ "' ";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}
		return mReturn;
	}
	
	public ObjectList detailquery16YKOutByProductType(String warehouseCode, String start, String end,String produtType) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}
		sql = sql + "from " + "t_out_head a," + "t_out_sub b,"
		+ "t_product_type c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " + "and b.product_id = c.product_id " + "and b.provider_code = d.code "
		+ "and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " + " and b.balance_mode = '" + ConstDefine.STR_YK
		+ "' "
		+ "and c.product_type = '"+produtType+"' ";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}
		return mReturn;
	}
	
	
	
	public ObjectList detailquery16YKOutByProductBidForGroup(String warehouseCode, String start, String end,String produtBidType) {
		String[] str=produtBidType.split(",");
		String sqlstr="";
		for(int i=0;i<str.length;i++){
			sqlstr+="'"+str[i]+"',";
		}
		sqlstr=sqlstr.substring(0,sqlstr.length()-1);
		
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}
		sql = sql + "from " + "t_out_head a," + "t_out_sub b,"
		+ "t_product_bid c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " + "and b.product_id = c.product_id " + "and b.provider_code = d.code "
		+ "and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " + "and b.balance_mode = '" + ConstDefine.STR_YK
		+ "' "
		+ "and c.product_type in ("+sqlstr+") ";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			System.out.println(sql);
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}
		return mReturn;
	}
	
	public ObjectList detailquery16YKOutByProductBidForGroupZxk(String warehouseCode, String start, String end,String produtBidType,String providerCode) {
		String[] str=produtBidType.split(",");
		String sqlstr="";
		String[] strzxk=providerCode.split(",");
		String sqlstrzxk="";
		for(int i=0;i<str.length;i++){
			sqlstr+="'"+str[i]+"',";
		}
		for(int i=0;i<strzxk.length;i++){
			sqlstrzxk+="'"+strzxk[i]+"',";
		}
		sqlstr=sqlstr.substring(0,sqlstr.length()-1);
		sqlstrzxk=sqlstrzxk.substring(0,sqlstrzxk.length()-1);
		
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}
		sql = sql + "from " + "t_out_head a," + "t_out_sub b,"
		+ "t_product_bid c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " + "and b.product_id = c.product_id " + "and b.provider_code = d.code "
		+ "and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " + "and b.balance_mode = '" + ConstDefine.STR_YK
		+ "' "
		+ "and c.product_type in ("+sqlstr+") and d.code in("+sqlstrzxk+")";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			System.out.println(sql);
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}
		return mReturn;
	}
	
	public ObjectList detailquery16YKOutByProductBid(String warehouseCode, String start, String end,String produtBidType) {
		String[] str=produtBidType.split(",");
		String sqlstr="";
		for(int i=0;i<str.length;i++){
			sqlstr+="'"+str[i]+"',";
		}
		sqlstr=sqlstr.substring(0,sqlstr.length()-1);
		
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}
		sql = sql + "from " + "t_out_head a," + "t_out_sub b,"
		+ "t_product_bid c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " + "and b.product_id = c.product_id " + "and b.provider_code = d.code "
		+ "and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " + "and b.balance_mode = '" + ConstDefine.STR_YK
		+ "' "
		+ "and c.product_type in ("+sqlstr+") ";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			System.out.println(sql);
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}
		return mReturn;
	}
	
	public ObjectList detailquery16MDInByProductBid(String warehouseCode, String start, String end,String productType) {
		
		String[] str=productType.split(",");
		String sqlstr="";
		for(int i=0;i<str.length;i++){
			sqlstr+="'"+str[i]+"',";
		}
		sqlstr=sqlstr.substring(0,sqlstr.length()-1);
		
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}

		sql = sql + "from " + "t_in_head a," + "t_in_sub b," + "t_product_bid c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.in_bill_id " + "and b.product_id = c.product_id " + "and a.provider_code = d.code "
		+
		"and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " + "and b.balance_mode = '" + ConstDefine.STR_MD
		+ "' "
		+ "and c.product_type in ("+sqlstr+") ";
		sql += " and a.in_time >= '" + start + "' and a.in_time <= '" + end + "'";

		DBConnection con = null;

		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			System.out.println(sql);
			ut.initial(con, sql);
			mReturn = ut.getList();

		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}

		return mReturn;
	}
	
	
	public ObjectList detailquery16MDInByProductBidForGroup(String warehouseCode, String start, String end,String productType) {
		String[] str=productType.split(",");
		String sqlstr="";
		for(int i=0;i<str.length;i++){
			sqlstr+="'"+str[i]+"',";
		}
		sqlstr=sqlstr.substring(0,sqlstr.length()-1);
		
		
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}

		sql = sql + "from " + "t_in_head a," + "t_in_sub b," + "t_product_bid c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.in_bill_id " + "and b.product_id = c.product_id " + "and a.provider_code = d.code "
		+
		"and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " + "and b.balance_mode = '" + ConstDefine.STR_MD
		+ "' "
		+ " and c.product_type in ("+sqlstr+") ";
		sql += " and a.in_time >= '" + start + "' and a.in_time <= '" + end + "'";

		DBConnection con = null;

		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			System.out.println(sql);
			ut.initial(con, sql);
			mReturn = ut.getList();

		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}

		return mReturn;
	}
	
	public ObjectList detailquery16MDInByProductBidForGroupZxk(String warehouseCode, String start, String end,String productType,String providerCode) {
		String[] str=productType.split(",");
		String sqlstr="";
		String[] strzxk=providerCode.split(",");
		String sqlstrzxk="";
		for(int i=0;i<str.length;i++){
			sqlstr+="'"+str[i]+"',";
		}
		for(int i=0;i<strzxk.length;i++){
			sqlstrzxk+="'"+strzxk[i]+"',";
		}
		sqlstr=sqlstr.substring(0,sqlstr.length()-1);
		sqlstrzxk=sqlstrzxk.substring(0,sqlstrzxk.length()-1);
		
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}

		sql = sql + "from " + "t_in_head a," + "t_in_sub b," + "t_product_bid c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.in_bill_id " + "and b.product_id = c.product_id " + "and a.provider_code = d.code "
		+
		"and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " + "and b.balance_mode = '" + ConstDefine.STR_MD
		+ "' "
		+ " and c.product_type in ("+sqlstr+") and d.code in("+sqlstrzxk+")";
		sql += " and a.in_time >= '" + start + "' and a.in_time <= '" + end + "'";

		DBConnection con = null;

		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			System.out.println(sql);
			ut.initial(con, sql);
			mReturn = ut.getList();

		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}

		return mReturn;
	}
	
	
	public ObjectList detailquery16MDInByProductType(String warehouseCode, String start, String end,String productType) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}

		sql = sql + "from " + "t_in_head a," + "t_in_sub b," + "t_product_type c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.in_bill_id " + "and b.product_id = c.product_id " + "and a.provider_code = d.code "
		+
		"and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " + " and b.balance_mode = '" + ConstDefine.STR_MD
		+ "' "
		+ "and c.product_type = '"+productType+"' ";
		sql += " and a.in_time >= '" + start + "' and a.in_time <= '" + end + "'";

		DBConnection con = null;

		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();

		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}

		return mReturn;
	}

	public ObjectList detailquery16MDIn(String warehouseCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		if (GSBaseConstants.PLANPRICE.equals("true")) {// 湖南巴士按实际价统计
			sql = sql + "b.product_count * b.actual_price money ";
		} else {
			sql = sql + "b.product_money money ";
		}

		sql = sql + "from " + "t_in_head a," + "t_in_sub b," + "t_product c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.in_bill_id " + "and b.product_id = c.id " + "and a.provider_code = d.code "
		+
		"and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " + "and b.balance_mode = '" + ConstDefine.STR_MD
		+ "' ";
		sql += " and a.in_time >= '" + start + "' and a.in_time <= '" + end + "'";

		DBConnection con = null;

		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();

		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}

		return mReturn;
	}
	//报表19结束

	/**
	 * 报表19 供应商应付款月报
	 * 
	 * @param aList
	 * @param title
	 * @param falseListLun 
	 * @param trueListLun 
	 * @param falseList 
	 * @param trueListYou 
	 * @param falseAirFour 
	 * @param trueAirFour 
	 * @param start
	 * @param end
	 */
	private void writeExcel_ReportProvider(String title, String fileName, ObjectList aList, ObjectList aListTrue, ObjectList aListFalse, String title1,
			String date, HttpServletRequest request, HttpServletResponse response,ObjectList aListTrueFour,ObjectList aListFalseFour, ObjectList trueListYou, ObjectList falseListYou, ObjectList trueListLun, ObjectList falseListLun, ObjectList trueAir, ObjectList falseAir,ObjectList trueListBus,ObjectList falseListBus,ObjectList zxkDianPingtrueList,ObjectList zxkDianPingfalseList) {
		ServletOutputStream out = null;
		try {
			HSSFWorkbook tWb = new HSSFWorkbook();
			HSSFSheet tSheet = tWb.createSheet();
			HSSFRow tRow = null;
			Region region = null;
			tSheet.setColumnWidth((short) 0, (short) (16 * 256));
			tSheet.setColumnWidth((short) 1, (short) (12 * 256));
			tSheet.setColumnWidth((short) 2, (short) (12 * 256));
			tSheet.setColumnWidth((short) 3, (short) (12 * 256));
			tSheet.setColumnWidth((short) 4, (short) (12 * 256));

			tWb.setSheetName(0, title1, HSSFCell.ENCODING_UTF_16);

			HSSFFont font = tWb.createFont();
			font.setFontHeightInPoints((short) 9);
			font.setFontName("宋体");
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

			HSSFCellStyle cStyle = tWb.createCellStyle();
			cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			HSSFCellStyle cStyleM = tWb.createCellStyle();
			cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM.setFont(font);

			HSSFCellStyle cStyleM_R = tWb.createCellStyle();
			cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			cStyleM_R.setFont(font);

			// 标题行
			tRow = tSheet.createRow((short) 0);
			HSSFCell c0 = createCell(tWb, tRow, (short) 1, title1);
			c0.setCellStyle(cStyleM);
			// 日期行
			tRow = tSheet.createRow((short) 1);
			region = new Region(1, (short) 1, 1, (short) 2);
			tSheet.addMergedRegion(region);
			createCell(tWb, tRow, (short) 1, date, HSSFCellStyle.ALIGN_CENTER, false);

			// 表头行
			tRow = tSheet.createRow((short) 2);

			HSSFCell c1 = createCell(tWb, tRow, (short) 0, "供应商编码");
			HSSFCell c2 = createCell(tWb, tRow, (short) 1, "供应商名称");
			HSSFCell c3 = createCell(tWb, tRow, (short) 2, "压库领用");
			HSSFCell c4 = createCell(tWb, tRow, (short) 3, "买断入库金额");
			HSSFCell c5 = createCell(tWb, tRow, (short) 4, "总金额");

			c1.setCellStyle(cStyleM_R);
			c2.setCellStyle(cStyleM_R);
			c3.setCellStyle(cStyleM_R);
			c4.setCellStyle(cStyleM_R);
			c5.setCellStyle(cStyleM_R);
			short index = 2; // 当前所在行号
			double trueMoney = 0;
			double falseMoney = 0;
			double totalTrueMoney = 0;
			double totalFalseMoney = 0;
			double totalRowMoney = 0;
			double totalAllMoney = 0;
			String providerName = "";
			String providerCode = "";
			double runhuaTrueMoney = 0;
			double runhuaFalseMoney = 0;
			double runhuaRowMonty = 0;
			double runhuaAllMonty=0;
			
			double luntaiTrueMoney = 0;
			double luntaiFalseMoney = 0;
			double luntaiRowMonty = 0;
			double luntaiAllMonty=0;
			
			double fourTrueMoney = 0;
			double fourFalseMoney = 0;
			double fourRowMonty = 0;
			double fourAllMonty=0;
			
			double airTrueMoney = 0;
			double airFalseMoney = 0;
			double airRowMonty = 0;
			double airAllMonty=0;
			
			double volvoTrueMoney = 0;
			double volvoFalseMoney = 0;
			double volvoRowMonty = 0;
			double volvoAllMonty=0;
			//电瓶
			double dianpingTrueMoney = 0;
			double dianpingFalseMoney = 0;
			double dianpingRowMonty = 0;
			double dianpingAllMonty=0;
			
			//中心库电瓶
			double zxkDianpingTrueMoney = 0;
			double zxkDianpingFalseMoney = 0;
			double zxkDianpingRowMonty = 0;
			double zxkDianpingAllMonty=0;
			
			//车身专项整治
			double busTrueMoney = 0;
			double busFalseMoney = 0;
			double busRowMonty = 0;
			double busAllMonty=0;
			

			ArrayList runhuayouRow = new ArrayList();
			ArrayList luntaiRow = new ArrayList();
			ArrayList fourTypeRow = new ArrayList();
			ArrayList airRow = new ArrayList();
			ArrayList volvoRow = new ArrayList();
			ArrayList dianpingRow = new ArrayList();
			ArrayList zxkDianpingRow = new ArrayList();
			ArrayList busRow = new ArrayList();
			
			for (int i = 0; i < aList.size(); i++) {

				// -----------------------
				// 统计产品出入库总数及总价

				UniversalRow row = (UniversalRow) aList.get(i);
				
				if (aListTrue != null) {
					//VOLVO
					if("90001".equals(row.getString("PROVIDER_CODE"))){
						for (int j = 0; j < aListTrue.size(); j++) {
							UniversalRow rowTrue = (UniversalRow) aListTrue.get(j);
							if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
								volvoTrueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
							}
						}
					}else if("90186".equals(row.getString("PROVIDER_CODE"))){
							for (int j = 0; j < aListTrue.size(); j++) {
								UniversalRow rowTrue = (UniversalRow) aListTrue.get(j);
								if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
									dianpingTrueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
								}
							}
					}
					else{
						for (int j = 0; j < aListTrue.size(); j++) {
							UniversalRow rowTrue = (UniversalRow) aListTrue.get(j);
							if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
								trueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
								providerName = rowTrue.getString("NAME");
								providerCode = rowTrue.getString("CODE");
							}
						}
					}
				} else {
					trueMoney = 0;
					volvoTrueMoney=0;
					dianpingTrueMoney=0;
					
				}

				if (aListFalse != null) {
					//VOLVO
					if("90001".equals(row.getString("PROVIDER_CODE"))){
						for (int k = 0; k < aListFalse.size(); k++) {
							UniversalRow rowFalse = (UniversalRow) aListFalse.get(k);
							if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
								volvoFalseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
							}
						}
					}else if("90186".equals(row.getString("PROVIDER_CODE"))){
						for (int k = 0; k < aListFalse.size(); k++) {
							UniversalRow rowFalse = (UniversalRow) aListFalse.get(k);
							if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
								dianpingFalseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
							}
						}
					}
					else{
						for (int k = 0; k < aListFalse.size(); k++) {
							UniversalRow rowFalse = (UniversalRow) aListFalse.get(k);
							if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
								falseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
								providerName = rowFalse.getString("NAME");
								providerCode = rowFalse.getString("CODE");
							}
						}
					}
				} else {
					falseMoney = 0;
					volvoFalseMoney = 0;
					dianpingFalseMoney = 0;
				}

				//VOLVO
				if(volvoTrueMoney!=0||volvoFalseMoney!=0){
					String[] rowString = {"90001","申沃售后服务部",String.valueOf(volvoTrueMoney),String.valueOf(volvoFalseMoney),String.valueOf(volvoTrueMoney+volvoFalseMoney)};
					volvoRow.add(rowString);
				}
				//电瓶
				if(dianpingTrueMoney!=0||dianpingFalseMoney!=0){
					String[] rowString = {"90186","巴士物资电瓶",String.valueOf(dianpingTrueMoney),String.valueOf(dianpingFalseMoney),String.valueOf(dianpingTrueMoney+dianpingFalseMoney)};
					dianpingRow.add(rowString);
				}
				//中心库电瓶
				if (zxkDianPingtrueList != null) {
					for (int j = 0; j < zxkDianPingtrueList.size(); j++) {
						UniversalRow rowTrue = (UniversalRow) zxkDianPingtrueList.get(j);
						if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							trueMoney = DoubleUtil.sub(trueMoney, Double.parseDouble(rowTrue.getString("MONEY")));
							zxkDianpingTrueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
						}
					}
				} else {
					zxkDianpingTrueMoney = 0;
					
				}

				if (zxkDianPingfalseList != null) {
					for (int k = 0; k < zxkDianPingfalseList.size(); k++) {
						UniversalRow rowFalse = (UniversalRow) zxkDianPingfalseList.get(k);
						if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							falseMoney = DoubleUtil.sub(falseMoney,Double.parseDouble(rowFalse.getString("MONEY")));
							zxkDianpingFalseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
						}
					}
				} else {
					zxkDianpingFalseMoney = 0;
				}
				
				if(zxkDianpingTrueMoney!=0||zxkDianpingFalseMoney!=0){
					String[] rowString = {providerCode,providerName,String.valueOf(zxkDianpingTrueMoney),String.valueOf(zxkDianpingFalseMoney),String.valueOf(zxkDianpingTrueMoney+zxkDianpingFalseMoney)};
					zxkDianpingRow.add(rowString);
				}				
				//润滑油
				if (trueListYou != null) {
					for (int j = 0; j < trueListYou.size(); j++) {
						UniversalRow rowTrue = (UniversalRow) trueListYou.get(j);
						if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							trueMoney = DoubleUtil.sub(trueMoney, Double.parseDouble(rowTrue.getString("MONEY")));
							runhuaTrueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
						}
					}
				} else {
					runhuaTrueMoney = 0;
					
				}

				if (falseListYou != null) {
					for (int k = 0; k < falseListYou.size(); k++) {
						UniversalRow rowFalse = (UniversalRow) falseListYou.get(k);
						if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							falseMoney = DoubleUtil.sub(falseMoney,Double.parseDouble(rowFalse.getString("MONEY")));
							runhuaFalseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
						}
					}
				} else {
					runhuaFalseMoney = 0;
				}
				
				if(runhuaTrueMoney!=0||runhuaFalseMoney!=0){
					String[] rowString = {providerCode,providerName,String.valueOf(runhuaTrueMoney),String.valueOf(runhuaFalseMoney),String.valueOf(runhuaTrueMoney+runhuaFalseMoney)};
					runhuayouRow.add(rowString);
				}
				
				//轮胎
				if (trueListLun != null) {
					for (int j = 0; j < trueListLun.size(); j++) {
						UniversalRow rowTrue = (UniversalRow) trueListLun.get(j);
						if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							luntaiTrueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
							trueMoney = DoubleUtil.sub(trueMoney, Double.parseDouble(rowTrue.getString("MONEY")));
						}
					}
				} else {
					luntaiTrueMoney = 0;
					
				}

				if (falseListLun != null) {
					for (int k = 0; k < falseListLun.size(); k++) {
						UniversalRow rowFalse = (UniversalRow) falseListLun.get(k);
						if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							luntaiFalseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
							falseMoney = DoubleUtil.sub(falseMoney,Double.parseDouble(rowFalse.getString("MONEY")));
						}
					}
				} else {
					luntaiFalseMoney = 0;
				}
				
				if(luntaiTrueMoney!=0||luntaiFalseMoney!=0){
					String[] rowLunString = {providerCode,providerName,String.valueOf(luntaiTrueMoney),String.valueOf(luntaiFalseMoney),String.valueOf(luntaiTrueMoney+luntaiFalseMoney)};
					luntaiRow.add(rowLunString);
				}
				
				//空调
				if ( trueAir!= null) {
					for (int j = 0; j < trueAir.size(); j++) {
						UniversalRow rowTrue = (UniversalRow) trueAir.get(j);
						if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							airTrueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
							trueMoney = DoubleUtil.sub(trueMoney, Double.parseDouble(rowTrue.getString("MONEY")));
						}
					}
				} else {
					airTrueMoney = 0;
					
				}

				if (falseAir != null) {
					for (int k = 0; k < falseAir.size(); k++) {
						UniversalRow rowFalse = (UniversalRow) falseAir.get(k);
						if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							airFalseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
							falseMoney = DoubleUtil.sub(falseMoney,Double.parseDouble(rowFalse.getString("MONEY")));
						}
					}
				} else {
					airFalseMoney = 0;
				}
				
				if(airTrueMoney!=0||airFalseMoney!=0){
					String[] rowAirString = {providerCode,providerName,String.valueOf(airTrueMoney),String.valueOf(airFalseMoney),String.valueOf(airTrueMoney+airFalseMoney)};
					airRow.add(rowAirString);
				}
				
				
				//车身专项整治
				if ( trueListBus!= null) {
					for (int j = 0; j < trueListBus.size(); j++) {
						UniversalRow rowTrue = (UniversalRow) trueListBus.get(j);
						if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							busTrueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
							trueMoney = DoubleUtil.sub(trueMoney, Double.parseDouble(rowTrue.getString("MONEY")));
						}
					}
				} else {
					busTrueMoney = 0;
					
				}

				if (falseListBus != null) {
					for (int k = 0; k < falseListBus.size(); k++) {
						UniversalRow rowFalse = (UniversalRow) falseListBus.get(k);
						if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							busFalseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
							falseMoney = DoubleUtil.sub(falseMoney,Double.parseDouble(rowFalse.getString("MONEY")));
						}
					}
				} else {
					busFalseMoney = 0;
				}
				
				if(busTrueMoney!=0||busFalseMoney!=0){
					String[] rowBusString = {providerCode,providerName,String.valueOf(busTrueMoney),String.valueOf(busFalseMoney),String.valueOf(busTrueMoney+busFalseMoney)};
					busRow.add(rowBusString);
				}
				
				
				//审核类
				if ( aListTrueFour!= null) {
					for (int j = 0; j < aListTrueFour.size(); j++) {
						UniversalRow rowTrue = (UniversalRow) aListTrueFour.get(j);
						if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							fourTrueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
							trueMoney = DoubleUtil.sub(trueMoney, Double.parseDouble(rowTrue.getString("MONEY")));
						}
					}
				} else {
					fourTrueMoney = 0;
					
				}

				if (aListFalseFour != null) {
					for (int k = 0; k < aListFalseFour.size(); k++) {
						UniversalRow rowFalse = (UniversalRow) aListFalseFour.get(k);
						if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							fourFalseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
							falseMoney = DoubleUtil.sub(falseMoney,Double.parseDouble(rowFalse.getString("MONEY")));
						}
					}
				} else {
					fourFalseMoney = 0;
				}
				
				if(fourTrueMoney!=0||fourFalseMoney!=0){
					String[] rowFourString = {providerCode,providerName,String.valueOf(fourTrueMoney),String.valueOf(fourFalseMoney),String.valueOf(fourTrueMoney+fourFalseMoney)};
					fourTypeRow.add(rowFourString);
				}
				
				totalRowMoney =DoubleUtil.add(trueMoney,falseMoney);
				// 創建一行
				if(providerCode.equals("")||providerCode.equals("90001")||providerCode.equals("90186")||providerCode.equals("90226")||providerCode.equals("90227")){
					trueMoney = 0;
					falseMoney = 0;
					totalRowMoney = 0;
					luntaiTrueMoney = 0;
					luntaiFalseMoney = 0;
					runhuaTrueMoney = 0;
					runhuaFalseMoney = 0;
					fourFalseMoney = 0;
					fourTrueMoney = 0;
					airTrueMoney =0;
					airFalseMoney = 0;
					busTrueMoney =0;
					busFalseMoney = 0;
					volvoTrueMoney = 0;
					volvoFalseMoney = 0;
					dianpingTrueMoney = 0;
					dianpingFalseMoney = 0;
					zxkDianpingTrueMoney = 0;
					zxkDianpingFalseMoney = 0;
					continue;
				}
				
				if(StringUtil.showPrice(String.valueOf(totalRowMoney)).equals("0.00")){
					trueMoney = 0;
					falseMoney = 0;
					totalRowMoney = 0;
					luntaiTrueMoney = 0;
					luntaiFalseMoney = 0;
					runhuaTrueMoney = 0;
					runhuaFalseMoney = 0;
					fourFalseMoney = 0;
					fourTrueMoney = 0;
					airTrueMoney =0;
					airFalseMoney = 0;
					busTrueMoney =0;
					busFalseMoney = 0;
					volvoTrueMoney = 0;
					volvoFalseMoney = 0;
					dianpingTrueMoney = 0;
					dianpingFalseMoney = 0;
					zxkDianpingTrueMoney = 0;
					zxkDianpingFalseMoney = 0;
					continue;
				}
				tRow = tSheet.createRow((short) (index + 1));
				createCell(tWb, tRow, (short) 0, providerCode);
				createCell(tWb, tRow, (short) 1, providerName);
				createCell(tWb, tRow, (short) 2, StringUtil.showPrice(String.valueOf(trueMoney)));
				createCell(tWb, tRow, (short) 3, StringUtil.showPrice(String.valueOf(falseMoney)));
				createCell(tWb, tRow, (short) 4, StringUtil.showPrice(String.valueOf(totalRowMoney)));
				index++;			
				
				totalTrueMoney += trueMoney;
				totalFalseMoney += falseMoney;
				totalAllMoney += totalRowMoney;
				
				providerName = "";
				providerCode = "";
				trueMoney = 0;
				falseMoney = 0;
				totalRowMoney = 0;
				luntaiTrueMoney = 0;
				luntaiFalseMoney = 0;
				runhuaTrueMoney = 0;
				runhuaFalseMoney = 0;
				fourFalseMoney = 0;
				fourTrueMoney = 0;
				airTrueMoney =0;
				airFalseMoney = 0;
				busTrueMoney =0;
				busFalseMoney = 0;
				volvoTrueMoney = 0;
				volvoFalseMoney = 0;
				dianpingTrueMoney = 0;
				dianpingFalseMoney = 0;
				zxkDianpingTrueMoney = 0;
				zxkDianpingFalseMoney = 0;
			}

			// 总计行
			if (index >= 2) {
				tRow = tSheet.createRow((short) (index + 1));
				HSSFCell providerCell = tRow.createCell((short) 0);
				HSSFCell cell_6 = tRow.createCell((short) 1);
				HSSFCell cell_7 = tRow.createCell((short) 2);
				HSSFCell cell_8 = tRow.createCell((short) 3);
				HSSFCell cell_9 = tRow.createCell((short) 4);

				providerCell.setCellStyle(cStyleM_R);
				cell_6.setCellStyle(cStyleM_R);
				cell_7.setCellStyle(cStyleM_R);

				providerCell.setEncoding(HSSFCell.ENCODING_UTF_16);
				providerCell.setCellValue("小计:");
				cell_6.setCellValue("");
				cell_7.setCellValue(StringUtil.showPrice(String.valueOf(totalTrueMoney)));
				cell_8.setCellValue(StringUtil.showPrice(String.valueOf(totalFalseMoney)));
				cell_9.setCellValue(StringUtil.showPrice(String.valueOf(totalAllMoney)));
				index ++;
				
				if(volvoRow.size()>0){
					//TODO

					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell runhuayouCell = tRow.createCell((short) 0);
					
					runhuayouCell.setCellStyle(cStyleM_R);
					runhuayouCell.setEncoding(HSSFCell.ENCODING_UTF_16);
					runhuayouCell.setCellValue("申沃售后服务部：");
					index ++;
					index ++;
					for (int i = 0; i < volvoRow.size(); i++) {
							String[] rowString = (String[]) volvoRow.get(i);
							
							// 創建一行
							tRow = tSheet.createRow((short) (index + 1));
							createCell(tWb, tRow, (short) 0, rowString[0]);
							createCell(tWb, tRow, (short) 1, rowString[1]);
							createCell(tWb, tRow, (short) 2, StringUtil.showPrice(rowString[2]));
							createCell(tWb, tRow, (short) 3, StringUtil.showPrice(rowString[3]));
							createCell(tWb, tRow, (short) 4, StringUtil.showPrice(rowString[4]));
							index++;
							trueMoney = Double.parseDouble(rowString[2]);
							falseMoney = Double.parseDouble(rowString[3]);
							totalRowMoney +=  Double.parseDouble(rowString[4]);
							totalTrueMoney += trueMoney;
							totalFalseMoney += falseMoney;
							totalAllMoney += totalRowMoney;
							
							
							volvoTrueMoney += trueMoney;
							volvoFalseMoney += falseMoney;
							volvoRowMonty += trueMoney + falseMoney;
							volvoAllMonty += totalRowMoney;
							providerName = "";
							providerCode = "";
							trueMoney = 0;
							falseMoney = 0;
							totalRowMoney = 0;
						}
					
					
					tRow = tSheet.createRow((short) (index + 1));
					HSSFCell pc = tRow.createCell((short) 0);
					HSSFCell cell_10 = tRow.createCell((short) 1);
					HSSFCell cell_11 = tRow.createCell((short) 2);
					HSSFCell cell_12 = tRow.createCell((short) 3);
					HSSFCell cell_13 = tRow.createCell((short) 4);

					pc.setCellStyle(cStyleM_R);
					cell_10.setCellStyle(cStyleM_R);
					cell_11.setCellStyle(cStyleM_R);

					pc.setEncoding(HSSFCell.ENCODING_UTF_16);
					pc.setCellValue("小计:");
					cell_10.setCellValue("");
					cell_11.setCellValue(StringUtil.showPrice(String.valueOf(volvoTrueMoney)));
					cell_12.setCellValue(StringUtil.showPrice(String.valueOf(volvoFalseMoney)));
					cell_13.setCellValue(StringUtil.showPrice(String.valueOf(volvoRowMonty)));
					
					index ++;
					}
				if(dianpingRow.size()>0){
					//TODO

					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell runhuayouCell = tRow.createCell((short) 0);
					
					runhuayouCell.setCellStyle(cStyleM_R);
					runhuayouCell.setEncoding(HSSFCell.ENCODING_UTF_16);
					runhuayouCell.setCellValue("电瓶：");
					index ++;
					index ++;
					for (int i = 0; i < dianpingRow.size(); i++) {
							String[] rowString = (String[]) dianpingRow.get(i);
							
							// 創建一行
							tRow = tSheet.createRow((short) (index + 1));
							createCell(tWb, tRow, (short) 0, rowString[0]);
							createCell(tWb, tRow, (short) 1, rowString[1]);
							createCell(tWb, tRow, (short) 2, StringUtil.showPrice(rowString[2]));
							createCell(tWb, tRow, (short) 3, StringUtil.showPrice(rowString[3]));
							createCell(tWb, tRow, (short) 4, StringUtil.showPrice(rowString[4]));
							index++;
							trueMoney = Double.parseDouble(rowString[2]);
							falseMoney = Double.parseDouble(rowString[3]);
							totalRowMoney +=  Double.parseDouble(rowString[4]);
							totalTrueMoney += trueMoney;
							totalFalseMoney += falseMoney;
							totalAllMoney += totalRowMoney;
							
							
							dianpingTrueMoney += trueMoney;
							dianpingFalseMoney += falseMoney;
							dianpingRowMonty += trueMoney + falseMoney;
							dianpingAllMonty += totalRowMoney;
							providerName = "";
							providerCode = "";
							trueMoney = 0;
							falseMoney = 0;
							totalRowMoney = 0;
						}
					
					
					tRow = tSheet.createRow((short) (index + 1));
					HSSFCell pc = tRow.createCell((short) 0);
					HSSFCell cell_10 = tRow.createCell((short) 1);
					HSSFCell cell_11 = tRow.createCell((short) 2);
					HSSFCell cell_12 = tRow.createCell((short) 3);
					HSSFCell cell_13 = tRow.createCell((short) 4);

					pc.setCellStyle(cStyleM_R);
					cell_10.setCellStyle(cStyleM_R);
					cell_11.setCellStyle(cStyleM_R);

					pc.setEncoding(HSSFCell.ENCODING_UTF_16);
					pc.setCellValue("小计:");
					cell_10.setCellValue("");
					cell_11.setCellValue(StringUtil.showPrice(String.valueOf(dianpingTrueMoney)));
					cell_12.setCellValue(StringUtil.showPrice(String.valueOf(dianpingFalseMoney)));
					cell_13.setCellValue(StringUtil.showPrice(String.valueOf(dianpingRowMonty)));
					
					index ++;
					}
				//中心库电瓶
				if(zxkDianpingRow.size()>0){
					//TODO

					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell runhuayouCell = tRow.createCell((short) 0);
					
					runhuayouCell.setCellStyle(cStyleM_R);
					runhuayouCell.setEncoding(HSSFCell.ENCODING_UTF_16);
					runhuayouCell.setCellValue("中心库电瓶：");
					index ++;
					index ++;
					for (int i = 0; i < zxkDianpingRow.size(); i++) {
							String[] rowString = (String[]) zxkDianpingRow.get(i);
							
							// 創建一行
							tRow = tSheet.createRow((short) (index + 1));
							createCell(tWb, tRow, (short) 0, rowString[0]);
							createCell(tWb, tRow, (short) 1, rowString[1]);
							createCell(tWb, tRow, (short) 2, StringUtil.showPrice(rowString[2]));
							createCell(tWb, tRow, (short) 3, StringUtil.showPrice(rowString[3]));
							createCell(tWb, tRow, (short) 4, StringUtil.showPrice(rowString[4]));
							index++;
							trueMoney = Double.parseDouble(rowString[2]);
							falseMoney = Double.parseDouble(rowString[3]);
							totalRowMoney +=  Double.parseDouble(rowString[4]);
							totalTrueMoney += trueMoney;
							totalFalseMoney += falseMoney;
							totalAllMoney += totalRowMoney;
							
							
							zxkDianpingTrueMoney += trueMoney;
							zxkDianpingFalseMoney += falseMoney;
							zxkDianpingRowMonty += trueMoney + falseMoney;
							zxkDianpingAllMonty += totalRowMoney;
							providerName = "";
							providerCode = "";
							trueMoney = 0;
							falseMoney = 0;
							totalRowMoney = 0;
						}
					
					
					tRow = tSheet.createRow((short) (index + 1));
					HSSFCell pc = tRow.createCell((short) 0);
					HSSFCell cell_10 = tRow.createCell((short) 1);
					HSSFCell cell_11 = tRow.createCell((short) 2);
					HSSFCell cell_12 = tRow.createCell((short) 3);
					HSSFCell cell_13 = tRow.createCell((short) 4);

					pc.setCellStyle(cStyleM_R);
					cell_10.setCellStyle(cStyleM_R);
					cell_11.setCellStyle(cStyleM_R);

					pc.setEncoding(HSSFCell.ENCODING_UTF_16);
					pc.setCellValue("小计:");
					cell_10.setCellValue("");
					cell_11.setCellValue(StringUtil.showPrice(String.valueOf(zxkDianpingTrueMoney)));
					cell_12.setCellValue(StringUtil.showPrice(String.valueOf(zxkDianpingFalseMoney)));
					cell_13.setCellValue(StringUtil.showPrice(String.valueOf(zxkDianpingRowMonty)));
					
					index ++;
					}
				if(runhuayouRow.size()>0){
					//TODO

					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell runhuayouCell = tRow.createCell((short) 0);
					
					runhuayouCell.setCellStyle(cStyleM_R);
					runhuayouCell.setEncoding(HSSFCell.ENCODING_UTF_16);
					runhuayouCell.setCellValue("润滑油：");
					index ++;
					index ++;
					for (int i = 0; i < runhuayouRow.size(); i++) {
							String[] rowString = (String[]) runhuayouRow.get(i);
							
							// 創建一行
							tRow = tSheet.createRow((short) (index + 1));
							createCell(tWb, tRow, (short) 0, rowString[0]);
							createCell(tWb, tRow, (short) 1, rowString[1]);
							createCell(tWb, tRow, (short) 2, StringUtil.showPrice(rowString[2]));
							createCell(tWb, tRow, (short) 3, StringUtil.showPrice(rowString[3]));
							createCell(tWb, tRow, (short) 4, StringUtil.showPrice(rowString[4]));
							index++;
							trueMoney = Double.parseDouble(rowString[2]);
							falseMoney = Double.parseDouble(rowString[3]);
							totalRowMoney +=  Double.parseDouble(rowString[4]);
							totalTrueMoney += trueMoney;
							totalFalseMoney += falseMoney;
							totalAllMoney += totalRowMoney;
							
							
							runhuaTrueMoney += trueMoney;
							runhuaFalseMoney += falseMoney;
							runhuaRowMonty += trueMoney + falseMoney;
							runhuaAllMonty += totalRowMoney;
							providerName = "";
							providerCode = "";
							trueMoney = 0;
							falseMoney = 0;
							totalRowMoney = 0;
						}
					
					
					tRow = tSheet.createRow((short) (index + 1));
					HSSFCell pc = tRow.createCell((short) 0);
					HSSFCell cell_10 = tRow.createCell((short) 1);
					HSSFCell cell_11 = tRow.createCell((short) 2);
					HSSFCell cell_12 = tRow.createCell((short) 3);
					HSSFCell cell_13 = tRow.createCell((short) 4);

					pc.setCellStyle(cStyleM_R);
					cell_10.setCellStyle(cStyleM_R);
					cell_11.setCellStyle(cStyleM_R);

					pc.setEncoding(HSSFCell.ENCODING_UTF_16);
					pc.setCellValue("小计:");
					cell_10.setCellValue("");
					cell_11.setCellValue(StringUtil.showPrice(String.valueOf(runhuaTrueMoney)));
					cell_12.setCellValue(StringUtil.showPrice(String.valueOf(runhuaFalseMoney)));
					cell_13.setCellValue(StringUtil.showPrice(String.valueOf(runhuaRowMonty)));
					
					index ++;
					}
				if(luntaiRow.size()>0){

					
					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell runhuayouCell = tRow.createCell((short) 0);
					
					runhuayouCell.setCellStyle(cStyleM_R);
					runhuayouCell.setEncoding(HSSFCell.ENCODING_UTF_16);
					runhuayouCell.setCellValue("轮胎：");
					index ++;
					index ++;
					for (int i = 0; i < luntaiRow.size(); i++) {
							String[] rowString = (String[]) luntaiRow.get(i);
							
							// 創建一行
							tRow = tSheet.createRow((short) (index + 1));
							createCell(tWb, tRow, (short) 0, rowString[0]);
							createCell(tWb, tRow, (short) 1, rowString[1]);
							createCell(tWb, tRow, (short) 2, StringUtil.showPrice(rowString[2]));
							createCell(tWb, tRow, (short) 3, StringUtil.showPrice(rowString[3]));
							createCell(tWb, tRow, (short) 4, StringUtil.showPrice(rowString[4]));
							index++;
							trueMoney = Double.parseDouble(rowString[2]);
							falseMoney = Double.parseDouble(rowString[3]);
							totalRowMoney +=  Double.parseDouble(rowString[4]);
							totalTrueMoney += trueMoney;
							totalFalseMoney += falseMoney;
							totalAllMoney += totalRowMoney;
							
							luntaiTrueMoney += trueMoney;
							luntaiFalseMoney += falseMoney;
							luntaiRowMonty += trueMoney + falseMoney;
							luntaiAllMonty +=totalRowMoney;
							
							providerName = "";
							providerCode = "";
							trueMoney = 0;
							falseMoney = 0;
							totalRowMoney = 0;
						}
					tRow = tSheet.createRow((short) (index + 1));
					HSSFCell pc = tRow.createCell((short) 0);
					HSSFCell cell_10 = tRow.createCell((short) 1);
					HSSFCell cell_11 = tRow.createCell((short) 2);
					HSSFCell cell_12 = tRow.createCell((short) 3);
					HSSFCell cell_13 = tRow.createCell((short) 4);

					pc.setCellStyle(cStyleM_R);
					cell_10.setCellStyle(cStyleM_R);
					cell_11.setCellStyle(cStyleM_R);

					pc.setEncoding(HSSFCell.ENCODING_UTF_16);
					pc.setCellValue("小计:");
					cell_10.setCellValue("");
					cell_11.setCellValue(StringUtil.showPrice(String.valueOf(luntaiTrueMoney)));
					cell_12.setCellValue(StringUtil.showPrice(String.valueOf(luntaiFalseMoney)));
					cell_13.setCellValue(StringUtil.showPrice(String.valueOf(luntaiRowMonty)));

					index ++;
					
				}
				if(airRow.size()>0){
	
					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell runhuayouCell = tRow.createCell((short) 0);
					
					runhuayouCell.setCellStyle(cStyleM_R);
					runhuayouCell.setEncoding(HSSFCell.ENCODING_UTF_16);
					runhuayouCell.setCellValue("空调：");
					index ++;
					index ++;
					for (int i = 0; i < airRow.size(); i++) {
							String[] rowString = (String[]) airRow.get(i);
							
							// 創建一行
							tRow = tSheet.createRow((short) (index + 1));
							createCell(tWb, tRow, (short) 0, rowString[0]);
							createCell(tWb, tRow, (short) 1, rowString[1]);
							createCell(tWb, tRow, (short) 2, StringUtil.showPrice(rowString[2]));
							createCell(tWb, tRow, (short) 3, StringUtil.showPrice(rowString[3]));
							createCell(tWb, tRow, (short) 4, StringUtil.showPrice(rowString[4]));
							index++;
							trueMoney = Double.parseDouble(rowString[2]);
							falseMoney = Double.parseDouble(rowString[3]);
							totalRowMoney +=  Double.parseDouble(rowString[4]);
							totalTrueMoney += trueMoney;
							totalFalseMoney += falseMoney;
							totalAllMoney += totalRowMoney;
							
							airTrueMoney += trueMoney;
							airFalseMoney += falseMoney;
							airRowMonty += trueMoney + falseMoney;
							airAllMonty +=totalRowMoney;
							
							providerName = "";
							providerCode = "";
							trueMoney = 0;
							falseMoney = 0;
							totalRowMoney = 0;
						}
					tRow = tSheet.createRow((short) (index + 1));
					HSSFCell pc = tRow.createCell((short) 0);
					HSSFCell cell_10 = tRow.createCell((short) 1);
					HSSFCell cell_11 = tRow.createCell((short) 2);
					HSSFCell cell_12 = tRow.createCell((short) 3);
					HSSFCell cell_13 = tRow.createCell((short) 4);

					pc.setCellStyle(cStyleM_R);
					cell_10.setCellStyle(cStyleM_R);
					cell_11.setCellStyle(cStyleM_R);

					pc.setEncoding(HSSFCell.ENCODING_UTF_16);
					pc.setCellValue("小计:");
					cell_10.setCellValue("");
					cell_11.setCellValue(StringUtil.showPrice(String.valueOf(airTrueMoney)));
					cell_12.setCellValue(StringUtil.showPrice(String.valueOf(airFalseMoney)));
					cell_13.setCellValue(StringUtil.showPrice(String.valueOf(airRowMonty)));

					index ++;
					
				}
				
				if(fourTypeRow.size()>0){

					tRow = tSheet.createRow((short) (index + 2));
					HSSFCell runhuayouCell = tRow.createCell((short) 0);
					
					runhuayouCell.setCellStyle(cStyleM_R);
					runhuayouCell.setEncoding(HSSFCell.ENCODING_UTF_16);
					runhuayouCell.setCellValue("审核统计：");
					index ++;
					index ++;
					
					for (int i = 0; i < fourTypeRow.size(); i++) {

						// -----------------------
						// 统计产品出入库总数及总价

						String[] rowString = (String[])fourTypeRow.get(i);
						
						
						// 創建一行
						tRow = tSheet.createRow((short) (index + 1));
						createCell(tWb, tRow, (short) 0, rowString[0]);
						createCell(tWb, tRow, (short) 1, rowString[1]);
						createCell(tWb, tRow, (short) 2, StringUtil.showPrice(rowString[2]));
						createCell(tWb, tRow, (short) 3, StringUtil.showPrice(rowString[3]));
						createCell(tWb, tRow, (short) 4, StringUtil.showPrice(rowString[4]));
						index++;
						trueMoney = Double.parseDouble(rowString[2]);
						falseMoney = Double.parseDouble(rowString[3]);
						
						totalTrueMoney += trueMoney;
						totalFalseMoney += falseMoney;
						totalRowMoney += trueMoney +falseMoney;
						totalAllMoney += totalRowMoney;
						
						fourTrueMoney += trueMoney;
						fourFalseMoney += falseMoney;
						fourRowMonty += trueMoney + falseMoney;
						fourAllMonty += fourRowMonty;
						
						providerName = "";
						providerCode = "";
						trueMoney = 0;
						falseMoney = 0;
						totalRowMoney = 0;
					}
					
					tRow = tSheet.createRow((short) (index + 1));
					HSSFCell providerCell2 = tRow.createCell((short) 0);
					HSSFCell cell_21 = tRow.createCell((short) 1);
					HSSFCell cell_22 = tRow.createCell((short) 2);
					HSSFCell cell_23 = tRow.createCell((short) 3);
					HSSFCell cell_24 = tRow.createCell((short) 4);

					providerCell2.setCellStyle(cStyleM_R);
					cell_21.setCellStyle(cStyleM_R);
					cell_22.setCellStyle(cStyleM_R);

					providerCell2.setEncoding(HSSFCell.ENCODING_UTF_16);
					providerCell2.setCellValue("小计:");
					cell_21.setCellValue("");
					cell_22.setCellValue(StringUtil.showPrice(String.valueOf(fourTrueMoney)));
					cell_23.setCellValue(StringUtil.showPrice(String.valueOf(fourFalseMoney)));
					cell_24.setCellValue(StringUtil.showPrice(String.valueOf(fourRowMonty)));
					index ++;

			}
			}
			tRow = tSheet.createRow((short) (index + 2));
			HSSFCell zongjiCell = tRow.createCell((short) 0);
			HSSFCell cell_1 = tRow.createCell((short) 1);
			HSSFCell cell_2 = tRow.createCell((short) 2);
			HSSFCell cell_3 = tRow.createCell((short) 3);
			HSSFCell cell_4 = tRow.createCell((short) 4);

			zongjiCell.setCellStyle(cStyleM_R);
			cell_1.setCellStyle(cStyleM_R);
			cell_2.setCellStyle(cStyleM_R);

			zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);
			zongjiCell.setCellValue("合计:");
			cell_1.setCellValue("");
			cell_2.setCellValue(StringUtil.showPrice(String.valueOf(totalTrueMoney)));
			cell_3.setCellValue(StringUtil.showPrice(String.valueOf(totalFalseMoney)));
			cell_4.setCellValue(StringUtil.showPrice(String.valueOf(totalAllMoney)));
			
			index++;
			index++;
			index++;
			index++;
			if(busRow.size()>0){
				
				tRow = tSheet.createRow((short) (index + 1));
				HSSFCell runhuayouCell = tRow.createCell((short) 0);
				
				runhuayouCell.setCellStyle(cStyleM_R);
				runhuayouCell.setEncoding(HSSFCell.ENCODING_UTF_16);
				runhuayouCell.setCellValue("车身专项整治：");
				index ++;
				for (int i = 0; i < busRow.size(); i++) {
						String[] rowString = (String[]) busRow.get(i);
						
						// 創建一行
						tRow = tSheet.createRow((short) (index + 1));
						createCell(tWb, tRow, (short) 0, rowString[0]);
						createCell(tWb, tRow, (short) 1, rowString[1]);
						createCell(tWb, tRow, (short) 2, StringUtil.showPrice(rowString[2]));
						createCell(tWb, tRow, (short) 3, StringUtil.showPrice(rowString[3]));
						createCell(tWb, tRow, (short) 4, StringUtil.showPrice(rowString[4]));
						index++;
						trueMoney = Double.parseDouble(rowString[2]);
						falseMoney = Double.parseDouble(rowString[3]);
						totalRowMoney +=  Double.parseDouble(rowString[4]);
						
						busTrueMoney += trueMoney;
						busFalseMoney += falseMoney;
						busRowMonty += trueMoney + falseMoney;
						busAllMonty +=totalRowMoney;
						
						providerName = "";
						providerCode = "";
						trueMoney = 0;
						falseMoney = 0;
						totalRowMoney = 0;
					}
				tRow = tSheet.createRow((short) (index + 1));
				HSSFCell pc = tRow.createCell((short) 0);
				HSSFCell cell_10 = tRow.createCell((short) 1);
				HSSFCell cell_11 = tRow.createCell((short) 2);
				HSSFCell cell_12 = tRow.createCell((short) 3);
				HSSFCell cell_13 = tRow.createCell((short) 4);

				pc.setCellStyle(cStyleM_R);
				cell_10.setCellStyle(cStyleM_R);
				cell_11.setCellStyle(cStyleM_R);

				pc.setEncoding(HSSFCell.ENCODING_UTF_16);
				pc.setCellValue("合计:");
				cell_10.setCellValue("");
				cell_11.setCellValue(StringUtil.showPrice(String.valueOf(busTrueMoney)));
				cell_12.setCellValue(StringUtil.showPrice(String.valueOf(busFalseMoney)));
				cell_13.setCellValue(StringUtil.showPrice(String.valueOf(busRowMonty)));

				index ++;
				
			}
			

			fileName = fileName + ".xls";
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();
			tWb.write(out);
			
			

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}
		}
	}
	public Map getRowDate(List typeName,List yk,List md,UniversalRow row ,double trueMoney,double falseMoney,String providerCode,String providerName)throws Exception{
        Map datas = new HashMap();     
		for(int i=0;i<yk.size();i++){ 
			String name =(String) typeName.get(i);
			ObjectList trueListYou = (ObjectList)yk.get(i); 
			ObjectList falseListYou = (ObjectList)md.get(i);
            	  List data = getRowDateForProvider(trueListYou, falseListYou, row, trueMoney, falseMoney, providerCode, providerName);
            	  if(data!=null&&data.size()>0){
            		  datas.put(name,data);
            	  }
              }
		return datas;
	}
	public List getRowDateForProvider(ObjectList trueListYou,ObjectList falseListYou,UniversalRow row ,double trueMoney,double falseMoney,String providerCode,String providerName)throws Exception{
		
		        double runhuaTrueMoney = 0;
		        double runhuaFalseMoney = 0;
		        List runhuayouRow = new ArrayList();
				if (trueListYou != null) {
					for (int j = 0; j < trueListYou.size(); j++) {
						UniversalRow rowTrue = (UniversalRow) trueListYou.get(j);
						if (rowTrue.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							trueMoney = DoubleUtil.sub(trueMoney, Double.parseDouble(rowTrue.getString("MONEY")));
							runhuaTrueMoney += Double.parseDouble(rowTrue.getString("MONEY"));
						}
					}
				} else {
					runhuaTrueMoney = 0;
					
				}

				if (falseListYou != null) {
					for (int k = 0; k < falseListYou.size(); k++) {
						UniversalRow rowFalse = (UniversalRow) falseListYou.get(k);
						if (rowFalse.getString("CODE").equals(row.getString("PROVIDER_CODE"))) {
							falseMoney = DoubleUtil.sub(falseMoney,Double.parseDouble(rowFalse.getString("MONEY")));
							runhuaFalseMoney += Double.parseDouble(rowFalse.getString("MONEY"));
						}
					}
				} else {
					runhuaFalseMoney = 0;
				}
				
				if(runhuaTrueMoney!=0||runhuaFalseMoney!=0){
					String[] rowString = {providerCode,providerName,String.valueOf(runhuaTrueMoney),String.valueOf(runhuaFalseMoney),String.valueOf(runhuaTrueMoney+runhuaFalseMoney)};
					runhuayouRow.add(rowString);
				}
		  return runhuayouRow;

	}
	public ObjectList detailquery20YKOut(String warehouseCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
		sql +="sum(b.product_money) money ";
		sql +="from " + "t_out_head a," + "t_out_sub b,"
		+ "t_product c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " + "and b.product_id = c.id " + "and b.provider_code = d.code "
		+ "and a.warehouse_code = '" + warehouseCode + "'  and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " + "and b.balance_mode = '" + ConstDefine.STR_YK
		+ "' ";
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "' group by d.name,d.code";
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery20 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}
		return mReturn;
	}

	public ObjectList detailquery20MDIn(String warehouseCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.name name," + "d.code code,";
			sql += "sum(b.product_money) money ";

		sql += "from " + "t_in_head a," + "t_in_sub b," + "t_product c,"
		+ // 修改供应商条件查询
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.in_bill_id " + "and b.product_id = c.id " + "and a.provider_code = d.code "
		+
		"and a.warehouse_code = '" + warehouseCode + "'  and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " + "and b.balance_mode = '" + ConstDefine.STR_MD
		+ "' ";
		sql += " and a.in_time >= '" + start + "' and a.in_time <= '" + end + "' group by d.name,d.code";

		DBConnection con = null;

		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();

		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16 error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {

			}
		}

		return mReturn;
	}
	
	/**
	 * 报表20产品供应商营运公司应付月报
	 * 
	 * @param aList
	 * @param title
	 * @param start
	 * @param end
	 */
	private void writeExcel_ReportProviderCustomer(String title, String fileName,ObjectList warehouseList, ObjectList aList, Map reportMap, String title1,
			String date, HttpServletRequest request, HttpServletResponse response) {
		ServletOutputStream out = null;
		//TODO
		try {
			HSSFWorkbook tWb = new HSSFWorkbook();
			HSSFSheet tSheet = tWb.createSheet();
			HSSFRow tRow = null;
			Region region = null;
			tSheet.setColumnWidth((short) 0, (short) (12 * 256));
			tSheet.setColumnWidth((short) 1, (short) (12 * 256));

			tWb.setSheetName(0, title1, HSSFCell.ENCODING_UTF_16);

			HSSFFont font = tWb.createFont();
			font.setFontHeightInPoints((short) 9);
			font.setFontName("宋体");
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

			HSSFCellStyle cStyle = tWb.createCellStyle();
			cStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			HSSFCellStyle cStyleM = tWb.createCellStyle();
			cStyleM.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM.setFont(font);

			HSSFCellStyle cStyleM_R = tWb.createCellStyle();
			cStyleM_R.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
			cStyleM_R.setFont(font);
			
			HSSFCellStyle cStyleM_A = tWb.createCellStyle();
			cStyleM_A.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			cStyleM_A.setFont(font);

			// 标题行
			tRow = tSheet.createRow((short) 0);
			HSSFCell c0 = createCell(tWb, tRow, (short) 1, title1);
			c0.setCellStyle(cStyleM);
			// 日期行
			tRow = tSheet.createRow((short) 1);
			region = new Region(1, (short) 1, 1, (short) 2);
			tSheet.addMergedRegion(region);
			createCell(tWb, tRow, (short) 1, date, HSSFCellStyle.ALIGN_CENTER, false);

			HSSFRow tRow1 = tSheet.createRow((short) 2);
			HSSFRow tRow2 = tSheet.createRow((short) 3);
			region = new Region(2, (short) 0, 3, (short) 0);
			tSheet.addMergedRegion(region);
			HSSFCell c1 = createCell(tWb, tRow1, (short) 0, "供应商名称");
			
			region = new Region(2, (short) 1, 3, (short) 1);
			tSheet.addMergedRegion(region);
			HSSFCell c5 = createCell(tWb, tRow1, (short) 1, "供应商编码");
			c1.setCellStyle(cStyleM);
			c5.setCellStyle(cStyleM);
			for (int j = 0; j < warehouseList.size(); j++) {
				Warehouse w = (Warehouse) warehouseList.get(j);
				HSSFCell c2 = createCell(tWb, tRow1, (short) (j*2+2), w.getName());
				region = new Region(2, (short) (2+j*2), 2, (short) (3+j*2));
				tSheet.addMergedRegion(region);
				c2.setCellStyle(cStyleM_A);
				HSSFCell c3 = createCell(tWb, tRow2, (short) (j*2+2), "压库出库");
				c3.setCellStyle(cStyleM_R);
				HSSFCell c4 = createCell(tWb, tRow2, (short) (j*2+3), "买断入库");
				c4.setCellStyle(cStyleM_R);
			}
			region = new Region(2, (short) (short)(warehouseList.size()*2+2),3,(short)(warehouseList.size()*2+2));
			tSheet.addMergedRegion(region);
			HSSFCell c6 = createCell(tWb, tRow1, (short)(warehouseList.size()*2+2), "合计");
			c6.setCellStyle(cStyleM_R);
			short index = 3; // 当前所在行号
			double totalHas = 0;
			double totalRowMoney = 0;
			for (int i = 0; i < aList.size(); i++) {
				String providerName = "";
				String providerCode = "";
				UniversalRow row = (UniversalRow) aList.get(i);
				providerCode = row.getString("PROVIDER_CODE");

				tRow = tSheet.createRow((short) (index + 1));
				
				createCell(tWb, tRow, (short) 1, providerCode);			
				for (int j = 0; j < warehouseList.size(); j++) {
					//TODO
					Warehouse w = (Warehouse) warehouseList.get(j);
					Object[] object = (Object[]) reportMap.get(providerCode+w.getCode());
					if(object == null){
						createCell(tWb, tRow, (short) (j*2+2), String.valueOf(""));
						createCell(tWb, tRow, (short) (j*2+3), String.valueOf(""));
					}else{
						String name = String.valueOf(object[2]);
						createCell(tWb, tRow, (short) (j*2+2), String.valueOf(object[0]));
						createCell(tWb, tRow, (short) (j*2+3), String.valueOf(object[1]));
						totalHas+= Double.parseDouble(String.valueOf(object[0]))+Double.parseDouble(String.valueOf(object[1]));
						if(!name.equals("")){
							providerName = name;
						}
					}
				}
				createCell(tWb, tRow, (short) 0, String.valueOf(providerName));
				createCell(tWb, tRow, (short)(warehouseList.size()*2+2), StringUtil.showPrice(String.valueOf(totalHas)));
				index++;
				if(totalHas==0){
					index--;
				}
				totalRowMoney += totalHas;
				totalHas = 0;
				
			}

			// 总计行
			if (index > 4) {
				tRow = tSheet.createRow((short) (index + 2));
				HSSFCell zongjiCell = tRow.createCell((short) 0);
				HSSFCell cell_1 = tRow.createCell((short) 1);
				zongjiCell.setCellStyle(cStyleM_R);
				cell_1.setCellStyle(cStyleM_R);
				zongjiCell.setEncoding(HSSFCell.ENCODING_UTF_16);
				zongjiCell.setCellValue("合计:");
				cell_1.setCellValue("");
				
				double[] totalDouble = new double[warehouseList.size()*2];
				for (int j = 0; j < warehouseList.size(); j++) {
					double totalInMoney = 0;
					double totalOutMoney = 0;
					
					Warehouse w = (Warehouse) warehouseList.get(j);
					for (int i = 0; i < aList.size(); i++) {
						UniversalRow row = (UniversalRow) aList.get(i);
						String providerCode = row.getString("PROVIDER_CODE");
						
						Object[] object = (Object[]) reportMap.get(providerCode+w.getCode());		
						totalOutMoney+= Double.parseDouble(String.valueOf(object[1]));
						totalInMoney+= Double.parseDouble(String.valueOf(object[0]));
						
					}
					totalDouble[j*2]=totalInMoney;
					totalDouble[j*2+1]=totalOutMoney;
				}
				
				for (int i = 0; i < totalDouble.length; i++) {
					HSSFCell c3;
					c3 = createCell(tWb, tRow, (short) (i+2), StringUtil.showPrice(String.valueOf(totalDouble[i])));
					c3.setCellStyle(cStyleM_R);
				}
				
				HSSFCell c8;
				c8 = createCell(tWb, tRow, (short)(warehouseList.size()*2+2), StringUtil.showPrice(String.valueOf(totalRowMoney)));
				c8.setCellStyle(cStyleM_R);
			}

			fileName = fileName + ".xls";
			response.setContentType("application/ms-excel");
			response.addHeader("Content-disposition", "filename=" + fileName);
			out = response.getOutputStream();
			tWb.write(out);

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}
		}
	}
	
	//报表20开始
	public ObjectList detailquery20Group(String warehouseCode, String start, String end) {
		ObjectList mReturn = ObjectList.getList();
		String sql = "select " + "d.code provider_code " + "from " + "t_out_head a," + "t_out_sub b," +
		"t_provider d " + "where " + "b.status = 1 " + "and a.id = b.out_bill_id " +
		"and b.provider_code = d.code " + // 修改供应商条件查询
		"and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302') " ;
		sql += " and a.out_time >= '" + start + "' and a.out_time <= '" + end + "'";
		sql += " group by d.code";
		sql += " union ";
		sql += "select " + "a.provider_code provider_code " + "from " + "t_in_head a," + "t_in_sub b " +
			 "where " + "b.status = 1 " + "and a.id = b.in_bill_id " +
			"and a.warehouse_code like '" + warehouseCode + "%' and a.warehouse_code not like '000005%' and a.warehouse_code not in ('00000202','00000300','00000301','00000302')  " ;
		sql += " and a.in_time >= '" + start + "' and a.in_time <= '" + end + "'";
		sql += " group by a.provider_code";
		
		DBConnection con = null;
		try {
			con = DBConnection.open(false);
			UniversalTable ut = new UniversalTable();
			ut.initial(con, sql);
			mReturn = ut.getList();
		} catch (Exception e) {
			System.out.println("ReportServlet SQL detailquery16Group error:" + e.getMessage());
		} finally {
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e1) {
			}
		}
		return mReturn;
	}
	
//	public boolean isZeroMoney(double out,double in){
//		if((int) Math.ceil(out)!=0||(int) Math.ceil(in)!=0){
//			return true;
//		}
//		return false;
//	}

}
